android listactivity onCheckedChangeListener

前端 未结 2 482
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-28 20:11

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 w

相关标签:
2条回答
  • 2021-01-28 20:19

    Use isItemChecked (int position) or setItemChecked(int position, boolean value) if you using standart array adapter and SINGLE or MULTIPLE choise mode. http://developer.android.com/reference/android/widget/AbsListView.html#isItemChecked(int)

    Also you can create your custom adapter and inflate row layout with checkbox that can hold onClickListener and CheckedChangedListener. Use search to find example.

    0 讨论(0)
  • 2021-01-28 20:31

    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
    }
    
                    }
                });
    
    0 讨论(0)
提交回复
热议问题