0

i want to implement a search Text to listView,

i load the listView items from server.

Currently, everytime that user enters something to the searchText i remove all items in the listView and add them again to the listView (if they contain the user entered string)

However it takes alot of time, to remove the whole listView and then start reload all items to list again

Therefore i want to loop all over the listView and to invisible the un-matched rows, is it possible? (something like View.GONE)

for example, i want to invisible the k-th item row in listView.

Also, i will want to change this item row to visible again.

thanks alot

Adir Rahamim
  • 453
  • 1
  • 12
  • 31
  • what about holding local copy of object, that you got from server and updating adapter?.. – Nickolai Astashonok Apr 09 '13 at 16:18
  • I also maintain it, however if i have about 100 items in the listView, it's alot of time to remove all of them and when the user doesnt want to search (the search text is empty) to add them again to the listView, can i invisible only spesific rows? – Adir Rahamim Apr 09 '13 at 16:20
  • maybe can i use: viewItem=listView.getChildAt(position); viewItem.setVisiblity(View.GONE); ?? – Adir Rahamim Apr 09 '13 at 16:38

1 Answers1

0

you don't need make the view invisible. Have a EdiText at the top. Then have filter for your listview and display items in listview accordingly. call notifydatasetchanged method to refresh listview.

An example of search on listview. http://www.androidhive.info/2012/09/android-adding-search-functionality-to-listview/

An example of listview with custom filter can be found in the link below

Search in ListView with EditText

Community
  • 1
  • 1
Raghunandan
  • 132,755
  • 26
  • 225
  • 256
  • thanks for answer, however i dont extend ArrayAdapter, i entends BaseAdapter, therefore i cant use the filter method... – Adir Rahamim Apr 09 '13 at 16:23
  • @AdirRahamim you can extend arrayadapter instead of base adapter and then make a search on the listview. – Raghunandan Apr 09 '13 at 16:26
  • hi, in ArrayAdapter i cant make a custom constructor, that's why i choosed to extends BaseAdapter – Adir Rahamim Apr 09 '13 at 16:27
  • when i try to implement a constructor it show me an error: "Implicit super constructor ArrayAdapter() is undefined. Must explicitly invoke another constructor" – Adir Rahamim Apr 09 '13 at 16:30
  • add super(parameters); in your adapter constructor. must be the 1st statement – Raghunandan Apr 09 '13 at 16:32
  • maybe can i use: viewItem=listView.getChildAt(position); viewItem.setVisiblity(View.GONE); ?? – Adir Rahamim Apr 09 '13 at 16:33
  • you can have custom constructor. add super in your constructor – Raghunandan Apr 09 '13 at 16:36
  • hi, i didnt understand you well, can you give me an example of what should i write? thanks in advance – Adir Rahamim Apr 09 '13 at 16:37
  • ma= new Myadapter(MainActivity.this,"hello", 9); then constructor public Myadapter(Context c,String s, int hello) { super(c, 0); System.out.println("................."+s+hello); } – Raghunandan Apr 09 '13 at 16:41
  • ok thanks, i also want to know answer for my second question (if you or another one knows): can i use: viewItem=listView.getChildAt(position); viewItem.setVisiblity(View.GONE); ?? – Adir Rahamim Apr 09 '13 at 16:46
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/27883/discussion-between-raghunandan-and-adir-rahamim) – Raghunandan Apr 09 '13 at 16:47
  • ok, i will accept your answer,please answer my questions in the chat, thanks alot :) – Adir Rahamim Apr 09 '13 at 17:02