I have an item layout like this, and set the background by using item selector
Just add
android:descendantFocusability="blocksDescendants"
To your top level LinearLayout of the listitem.
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);
}
Use setOnCheckedChangeListener
instead of onItemClickListne
r for checkbox
CheckBox check;
check=new CheckBox(this);
check.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
}
});
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?
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.