Selection not showing the correct item in the listview

Discussion in 'Android App Developers' started by aka001, Feb 29, 2016.

  1. aka001

    aka001 New Member

    Joined:
    Feb 29, 2016
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Ratings:
    +0
    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.png

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

    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();
                        
                    }
    

     
Search tags for this page

android listview select item and highlight it