Search code examples
androidsearchandroid-listviewsharedpreferences

How to save old position of an element in sharedpreferences after Search filtering the listview


I implemented the code for filtering and also saving the position of the selected element in the listview. After the user makes search in the listview via editText a new list is created. When the user clicks on the element the position of it is being saved in sharedpreferences. By reopening the app, this position is needed but not the position from the filtered listview. It should be the right position of the original one. I didnt find any way to do this in my code. I would really appreciate any help. Thank you.


Solution

  • Saving position is not a convenient way to achieve the solution. Rather you need to store any unique value of the list.

    Suppose, you are showing a list of Person and filtering the list based on user search. So, every Person will have one id say, p_idwhich is unique. Try to save p_id in your SharedPreference.

    Then after reopening the app check the p_id of original list and mark then check or uncheck.