Skip to content Skip to sidebar Skip to footer

Getcheckeditempositions() Always Returning Null (android Listview)

EDIT: Based on evolution of the problem, I edited this question. First of all, I know there some similar questions, but each one of them has a specific difference, that makes the a

Solution 1:

try this code

list = (ListView) findViewById(R.id.listagem);
list.setAdapter(newArrayAdapter<String>(this, R.layout.list_item,R.id.nomeAPP,aux));
list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

//get the checked Items like this;

int count=list.getChildCount();
for(int i=1;i<=count;i++){
     if(list.isItemChecked(i)){
         //do your task/work
    }
}

Solution 2:

You have to set the choiceMode attribute on your ListView in order to get an object back from this method:

http://developer.android.com/reference/android/widget/AbsListView.html#getCheckedItemPositions%28%29

Solution 3:

Your problem is that the custom row should implement Checkable. Read this question.

Solution 4:

Looks that was a bug in the use of setAdapter, which is solved using setListAdapter.

Let's see, documentation states that ListActivity should use

list=getListView();
<ListView android:id="@android:id/list"

so forget about = "+@id(....

now we can our activity knows "where" is the List and now we can use

setListAdapter(newArrayAdapter<String>(this, 
                      R.Layout.List_item, aux));

and everything works fine.

Post a Comment for "Getcheckeditempositions() Always Returning Null (android Listview)"