I need to allow multi select in a list view. I did it succesfully except for one problem.
Around 20 items are displayed when the list shows. u can go on selecting up till the 19th without any error.
When u click the 20th, the 21st gets selected, when u click the 21st the 24th, and when u click 24, then null pointer exception.
I am using this code for multiselect:
Using java Syntax Highlighting
childList.setOnItemClickListener(new OnItemClickListener() { @SuppressWarnings("unchecked") public void onItemClick(AdapterView av,View view, int position, long row_id) { /* * Every time an item in the list is clicked(center button), * then we add its id into selectedChildIds for use to either play or delete. */ String selItem = null; /* duplicateFlag determines whether the selected item was already selected before or not. * value 1: it was previously selected.. => unselect it (remove background) * value 0: it isnt selected.. => select it (set background) */ int duplicateFlag=0; try { selItem = childList.getSelectedItem().toString(); } catch (Exception e) { selItem = null; } if(selItem!=null) { int selItemId=-1; for(int j=0;j<childTitles.size();j++) if(selItem.equals(childTitles.get(j))) { selItemId = childIds.get(j); for(int k=0;k<selectedChildIds.size();k++) { if(Integer.valueOf(selectedChildIds.get(k))==selItemId) { duplicateFlag=1; break; } else duplicateFlag=0; } if(duplicateFlag==0) { selectedChildIds.add(((Integer)selItemId).toString()); selectedChildTitles.add(childTitles.get(j)); } else { int deletePosition = selectedChildIds.indexOf(((Integer)selItemId).toString()); selectedChildIds.remove(deletePosition); selectedChildTitles.remove(deletePosition); } break; } } View childTextView = childList.getChildAt(position); if(duplicateFlag==0) childTextView.setBackground(R.drawable.rect); else childTextView.setBackground(null); //null value removes background. } });Parsed in 0.037 seconds, using GeSHi 1.0.8.4
If problem is not clear then pls say so, i shall try to elaborate.
Kindly help,
Thanks.

