jeudi 25 mai 2017

Android ListView select first 10 items

In my android application I need to select first 10 items of a list view.when a checkbox is selected. I gave below code .. it is selecting 10 items only but not in the visible view.. So can anybody help me.. what change I need to do in this code

if (checked)
                  {                    
                      for(int i=0; i<lv.getAdapter().getCount();i++)
                      {
View c = lv.getChildAt(0);
                          final int firstListItemPosition = lv.getPositionForView(c);


                          final int lastListItemPosition = firstListItemPosition + 9;


                          if (i == firstListItemPosition || i < lastListItemPosition )
                          {
                              View vii = lv.getAdapter().getView(i, null, lv);
                              CheckBox cb = (CheckBox)vii.findViewById(R.id.selected);
                              cb.setChecked(true);
                          }
}




Aucun commentaire:

Enregistrer un commentaire