1. Are you ready for the Galaxy S20? Here is everything we know so far!

Filtered listview highlighting incorrect item

Discussion in 'Android Development' started by AKA001, Feb 26, 2016.

  1. AKA001

    AKA001 Newbie
    Thread Starter

    Hello,





    I have a list view where I am filtering items through a SearchView. on activating the state for an item, it is not getting the correct item instead getting it from the position. To make it more clear, please refer to the below screenshots:



    1. Searched for keyword com and selected the filtered item (i.e activated_state)
    filtered_item.png

    2. On clearing the filter, when the position of the items changes it does not keep track of the selected item:
    cleared_filter.png





    I want the selection to be correct regardless of the position change.



    My code in MainActivity for this section:


    Code (Text):
    1.  
    2.     apps.setChoiceMode(apps.CHOICE_MODE_MULTIPLE_MODAL);
    3.  
    4.             apps.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
    5.  
    6.                 [USER=1021285]@override[/USER]
    7.  
    8.                 public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
    9.  
    10.                  
    11.  
    12.  
    13.  
    14.                     if (apps.isItemChecked(position)) {
    15.  
    16.  
    17.  
    18.  
    19.  
    20.                         Adapter.getItem(position);
    21.  
    22.                         Toast.makeText(getApplicationContext(), "CHECKED", Toast.LENGTH_LONG).show();
    23.  
    24.  
    25.  
    26.                         count = count + 1;
    27.  
    28.                         mode.setTitle(count + "items selected");
    29.  
    30.  
    31.  
    32.  
    33.  
    34.                         list_apps.add(Adapter.filteredData.get(position).packageName);
    35.  
    36.  
    37.  
    38.  
    39.  
    40.  
    41.  
    42.                         list_apps.trimToSize();
    43.  
    44.  
    45.  
    46.                     }
    47.  
    48.  
    49.  
    50.                     else {
    51.  
    52.                         Toast.makeText(getApplicationContext(), "UNCHECKED" , Toast.LENGTH_LONG).show();
    53.  
    54.  
    55.  
    56.  
    57.  
    58.                         count--;
    59.  
    60.                         mode.setTitle(count + "items selected");
    61.  
    62.  
    63.  
    64.                         list_apps.remove(Adapter.filteredData.get(position).packageName);
    65.  
    66.  
    67.  
    68.  
    69.  
    70.                         list_apps.trimToSize();
    71.  
    72.  
    73.  
    74.                     }
    75.  
    76.  


    I am using an extended baseAdapter, please let me know if you need to see that code as well.
     


Loading...

Share This Page

Loading...