I am using ListView with CheckBox. I have selected only one CheckBox but it’s automatically selected into Multiple Rows using ScrollView.
Sample Code (This Code is working Perfectly)
holder.checkbox.setOnClickListener( new OnClickListener()
{
public void onClick( View v )
{
CheckBox cb = ( CheckBox ) v;
if ( cb.isChecked() )
{
test[position] = true;
holder.checkbox.setChecked(test[position]);
}
else
{
test[position] = false;
holder.checkbox.setChecked(test[position]);
}
}
});
holder.checkbox.setChecked(test[position]);
But When i uses setOnItemClickListener it’s not working.
Sample Code (This code is not working for me)
listview.setOnItemClickListener( new OnItemClickListener()
{
public void onItemClick( AdapterView<?> parent, final View v, final int position, long id )
{
holder.checkbox = ( CheckBox ) v.findViewById( R.id.lock_File_CheckBox );
if ( holder.checkbox.isChecked() )
{
test[position] = false;
holder.checkbox.setChecked(test[position]);
}
else
{
test[position] = true;
holder.checkbox.setChecked(test[position]);
}
}
});
holder.checkbox.setChecked(test[position]);
Where i can mistaken. How do avoid this CheckBox Selection.
Can you please help me?
You can get the instance of CheckBox inside
onItemClick()by usingsetTag()andgetTag(). You can setTag the CheckBox instance inside yourgetView()method asAnd get the instance inside
onItemClick()using,If you have any further query you can check
my blog post.