• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Filtered listview highlighting incorrect item

AKA001

Newbie
Feb 10, 2016
10
0
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:
    apps.setChoiceMode(apps.CHOICE_MODE_MULTIPLE_MODAL);

            apps.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {

                [USER=1021285]@override[/USER]

                public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {

                  

  

                    if (apps.isItemChecked(position)) {

  

  

                        Adapter.getItem(position);

                        Toast.makeText(getApplicationContext(), "CHECKED", Toast.LENGTH_LONG).show();

  

                        count = count + 1;

                        mode.setTitle(count + "items selected");

  

  

                        list_apps.add(Adapter.filteredData.get(position).packageName);

  

  

  

                        list_apps.trimToSize();

  

                    }

  

                    else {

                        Toast.makeText(getApplicationContext(), "UNCHECKED" , Toast.LENGTH_LONG).show();

  

  

                        count--;

                        mode.setTitle(count + "items selected");

  

                        list_apps.remove(Adapter.filteredData.get(position).packageName);

  

  

                        list_apps.trimToSize();

  

                    }



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

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones