OnItemClickListener was not work with the checkbox?

前端 未结 5 1251
青春惊慌失措
青春惊慌失措 2020-11-30 10:29

I have an item layout like this, and set the background by using item selector



        
相关标签:
5条回答
  • 2020-11-30 10:47

    Just add

    android:descendantFocusability="blocksDescendants"

    To your top level LinearLayout of the listitem.

    0 讨论(0)
  • 2020-11-30 10:50

    You could add this code within your OnItemClickListener method:

    public void onItemClick(AdapterView parent, View view, int position, long id){
       CheckBox box = (CheckBox)view.findViewById(R.id.course_search_checkbox);
       box.setChecked(true);
    }
    
    0 讨论(0)
  • 2020-11-30 10:50

    Use setOnCheckedChangeListener instead of onItemClickListner for checkbox

    CheckBox check;
    check=new CheckBox(this);
    check.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // TODO Auto-generated method stub
        }
    });
    
    0 讨论(0)
  • 2020-11-30 11:03

    The onItemClickListener for the listView will not work if you have any clickables like buttons, ImageButton, Checkbox, etc in the listView. Add

    mainListView.setItemsCanFocus(true);
    

    Refer ListView OnItemClickListener Not Responding?

    0 讨论(0)
  • 2020-11-30 11:05

    Best way to do this is set these following properties for your checkbox:

      android:focusable="false"
      android:focusableInTouchMode="false"
    

    I had a same issue and did this.

    0 讨论(0)
提交回复
热议问题