What's new
DroidForums.net | Android Forum & News

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Selection not showing the correct item in the listview

aka001

New Member
I am using multi choice mode to select the items in the listview with filter. After searching through the list view when I select an item it highlights a different position instead of the original position of the item in the list view.



for example:



1. With filter, I’ve selected the following item:
filtered_item.webp


2. On the main list view with no filter, it does not highlight the selected item, but the wrong one:
cleared_filter.webp


In the below code of my Main Activity, how can I achieve what I’m looking for:

Code:
ListView [B]list[/B];

[B]apps[/B].setChoiceMode([B]apps[/B].[B][I]CHOICE_MODE_MULTIPLE_MODAL[/I][/B]);
        [B]apps[/B].setMultiChoiceModeListener([B]new [/B]AbsListView.MultiChoiceModeListener() {
            @Override
            [B]public void [/B]onItemCheckedStateChanged(ActionMode mode, [B]final int [/B]position, [B]long [/B]id, [B]boolean [/B]checked) {


[I]//If the item is selected in the listview list
                [/I][B]if [/B]([B]list[/B].isItemChecked(position)) {


                Toast.[I]makeText[/I](getApplicationContext(), [B]"CHECKED" [/B], Toast.[B][I]LENGTH_LONG[/I][/B]).show();



//how can I maintain the original position of the filtered item????[I]

            [/I]

                }

//[I]If the selection is removed for the item in the listview list[/I]
                [B]else [/B]{
                    Toast.[I]makeText[/I](getApplicationContext(), [B]"UNCHECKED" [/B], Toast.[B][I]LENGTH_LONG[/I][/B]).show();
                    
                }
 
Back
Top