0

我想创建一个自定义多项选择列表视图,任何人都可以帮忙。

在我的情况下,有一个自定义布局,其中包含四个文本视图和一个复选框。

这是我的代码

https://stackoverflow.com/a/10561814/1381622


这是我的代码

public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.take_order);

    addToOrder=(Button)findViewById(R.id.addToOrder);
    order=(Button)findViewById(R.id.order);
    back=(ImageButton)findViewById(R.id.back);
    buttonSeperator=(ImageView)findViewById(R.id.buttonSeperator);

    spTable=(Spinner)findViewById(R.id.tableNo);
    ArrayAdapter<CharSequence> adapter=ArrayAdapter.createFromResource(this,R.array.tableList,android.R.layout.simple_spinner_item);

    adapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
    spTable.setAdapter(adapter);
    spTable.setOnItemSelectedListener(this);

    categoryList=(ListView)findViewById(R.id.foodCategoryList);
    //categoryList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    //categoryList.setItemsCanFocus(false);




    fc=new FoodCategory();


    categoryAdapter=fc.new FoodAdapter(this,R.layout.food_category_list,fc.list);

    categoryList.setAdapter(categoryAdapter);
    categoryList.setOnItemClickListener(this);


}

    @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
    fl=new FoodList();

    order.setVisibility(View.GONE);
    addToOrder.setVisibility(View.VISIBLE);
    back.setVisibility(View.VISIBLE);
    buttonSeperator.setVisibility(View.VISIBLE);



        fl.bundleCategory=fc.list[position];
        fl.foodListService();

        WaiterFoodAdapter foodAdapter=new WaiterFoodAdapter(this, R.layout.take_order_list, fl.foodList);
        categoryList.setAdapter(foodAdapter);
        categoryList.setOnItemClickListener(this);


}

实际上我使用一个列表视图,当用户单击列表视图时,我在同一个列表视图中设置了另一个适配器......并且

public void back(View v)
{
    addToOrder.setVisibility(View.GONE);
    back.setVisibility(View.GONE);
    buttonSeperator.setVisibility(View.GONE);
    order.setVisibility(View.VISIBLE);

    categoryList.setAdapter(categoryAdapter);       
}

当用户单击返回按钮时,我再次设置旧适配器,,,,第二个适配器列表视图无法单击,我不知道为什么?

4

1 回答 1

1

请参考以下链接:

http://appfulcrum.com/2010/09/18/listview-example-4-custom-layout-checkbox-imagebutton-textview/

于 2012-05-08T09:44:37.233 回答