安卓listactivity onCheckedChangeListenerlistactivity、onCheckedChangeListener

2023-09-04 04:55:02 作者:彪悍的菇凉

我开发一个应用程序,我有一个 ListActivity ,其选择模式设置为 choice_mode_multiple 。现在我想覆盖的方法,这就是所谓当一个产品的选中/取消选中的,而且我发现, onCheckChanged()方法只为 RadioGroup中实施和复方按钮。我怎么可以覆盖这样的事情在 ListActivity ?还是我要实现我自己的适配器?谢谢

I'm developing an app and I have one ListActivity, which has choice mode set to choice_mode_multiple. now i want to override method, which is called when one item is checked/unchecked, and I've found out that onCheckChanged() method is implemented only for RadioGroup and compund Button. how can I override something like this in ListActivity? or do I have to implement my own Adapter? thanks

推荐答案

设置onlistitemclick监听器的ListView,然后在itemClick在方法,你可以得到mylistView.getCheckedItemCount(),写操作的code被执行。

Set onlistitemclick listener to listview , then in itemclick method you can get mylistView.getCheckedItemCount() , write the code of the operation to be performed.

如果这是不明确让我知道你想实现当项目被选中的东西。

If this is not clear let me know what you want to implement when item is checked.

mylistView = (ListView)customView.findViewById(R.id.mylist);
mylistView.setAdapter(mFolderAdapter);

mylistView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);


mylistView.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> arg0, View v,
                        int arg2, long arg3) {
                    // TODO Auto-generated method stub



                        if(mylistView.isItemChecked(arg2)){

  //Dooperation

                            } 
// or 
if(mylistView.getCheckedItemCount()>1){
  //Dooperation
}

                }
            });