My ListView contains Ten Rows. Each rows contained the CheckBox. How would I check and uncheck the CheckBox using setOnItemClickListener
Sample Code : (it’s not working for me)
listview.setOnItemClickListener( new OnItemClickListener()
{
public void onItemClick( AdapterView<?> parent, final View v, final int position, long id )
{
Toast.makeText( this, " Position is " + position, Toast.LENGTH_SHORT ) .show();
holder.checkbox = ( CheckBox ) v.findViewById( R.id.lock_File_CheckBox );
holder.checkbox.toggle();
}
});
How do we find whether CheckBox is checked or unchecked?
To get the instance of Checkbox inside
onItemClick()you need to usesetTag()andgetTag()for checkbox instance. You can checkmy example on my blogthat shows how we can get the instance of CheckBox insideonItemClick().After getting your CheckBox instance inside
onItemClick()update your content of list and notify your adapter insideonItemClick()as,