Reputation: 2073
I have a listview in which I am getting values from base adapter.what I want that on a click of button, check boxes whose property is invisible gets visible and get appear in front of each row of the list view.I am able to work this thing out but getting check boxes in front of few rows only. I am tired of searching for this thing.I feel problem is somewhere in getting the list view which only fetches view for the rows which are visible on the screen at the time.as I am quite new in this field, I am unable to get my exact problem.any help would be highly appreciable.
///check boxes are appearing in the four rows then again after the gap of two rows and so on..///
button.setOnClickListener(this);
public void onClick(View v) {
// TODO Auto-generated method stub
//relative layout in which button is declared
RelativeLayout relative=(RelativeLayout)v.getParent();
//listview is first child of relative..
ListView lv=(ListView)relative.getChildAt(1);
for(int i=0;i<lv.getChildCount();i++){
////////relative layout in whichcheckbox is declared
RelativeLayout newrelative=(RelativeLayout)lv.getChildAt(i);
//checkbox is forth child of newrelative..
CheckBox cb=(CheckBox)newrelative.getChildAt(4);
cb.setVisibility(0);
}
}//method
Upvotes: 0
Views: 734
Reputation: 2243
ListView
widget recycles its views and that's why you see changes when you scroll up and down.
to solve it you should Override your list adapter and in it decide whether or not to display the Checkbox
.
the best way to do that is probably saving this data in a database.
then inside the getView method you should add -
if (*i should see a checkbox next to this item*) {
checkbox.setVisibility(View.VISIBLE);
} else {
checkbox.setVisibility(View.INVISIBLE);
}
the "else" is important because otherwise it will reuse a visible enter code here
Checkbox with an item that you dont want to have an Checkbox
.
hope it helps.
Upvotes: 2
Reputation: 386
you can get a detailed step by step tutorial for checkbox listview at..checkbox listview tutorial.
Upvotes: 0