Android Question Forced to Use ExitApplication When Working With SearchView

Mahares

Expert
Licensed User
Longtime User
I have a searchview list (SearchView Class) that displays records from a field in a SQLite table. Its index is created in Activity_Create with FirstTime=True. The displayed data occupies one page of an AHviewPager. In the adjacent AHViewPager page I import a text file to replace the entire content of the table. When I go back to the first page and do another search, the original content of the table before the replacement is what displays rather than the new data I just imported. Even after closing cursor and database object and Activity.Finish the program and reentering, it is still displaying the old data in the searchview result.
The only way I got rid of the old data in the search list was to either force close the app or to use ExitApplication to kill the app and start over. This does not seem like a healthy way of doing it. How can I get rid of the old data and have the searchview use the newly imported data in the table search result?
Thank you for any constructive tips.
 

Mahares

Expert
Licensed User
Longtime User
2. Remove the current SearchView instance and create a new one.
I am not sure if this is what you wanted me to do. Here is my code immediately after I import the new text file into the table. It seems to work, but if you have something else in mind, please steer me to a better solution:
B4X:
MyListSearch.Initialize      'list
txt="SELECT NAME, NO, CLASS FROM tblTable ORDER BY NAME"
Cursor1=SQL1.ExecQuery(txt)
For i=0 ToCursor1.RowCount-1
  Cursor1.Position = I
  MyListSearch.Add(Cursor1.GetString("NAME") & TAB & TAB & Cursor1.GetString("NO") _
  & TAB & TAB & Cursor1.GetString("CLASS") )
Next
index = sv.SetItems(MyListSearch)      'Dim sv As SearchView in Global
SQL1.Close
Activity.Finish
Return
Thank you a bunch.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I recommend you to add a Clear sub to SearchView and then call Clear followed by SetItems
.
Doesn't putting this line in my main code do just what you instruct me to do (clears the old list and map): index = sv.SetItems(MyListSearch)
All I do in my above code is reinitialize the list, then import the new table field data to the list and recreate the items index. That is how I understood your recommendation. if not, can you offer some code here on how to do it the proper way.
Thanks
 
Last edited:
Upvote 0
Top