0

I am trying to retrieve all member data from my database and then display it on a listview and it is able to work.

Now I am trying to search for a particular member and i managed to retrieve the records (logged into the logcat) but it doesn't refresh my listview accordingly.

This is the list view codes I used to retrieve the searched records.

            SimpleAdapter simpleAdapter = new SimpleAdapter(Search.this, productsList, R.layout.list_item, new String[] {TAG_COMPANY},
                    new int[] { R.id.name});
            lv = (ListView) findViewById(R.id.lst_name);
            lv.setAdapter(simpleAdapter);
Jolene
  • 149
  • 2
  • 5
  • 14
  • adapter.notifyDataSetChanged(); Try this after search. – Raghunandan Nov 09 '12 at 02:59
  • place "adapter.notifyDataSetChanged();" after my search and then still use the above codes to retrieve it? or.. – Jolene Nov 09 '12 at 03:51
  • You have a edittext and you want to search the listview?? If that's the case use a custom filter. The below answer should help you. Also have a look at this link http://stackoverflow.com/questions/13090046/how-to-implement-search-in-customlistview-based-on-class-item-of-pojo-class-in-a. But adapter.notifyDataSetChanged(); is used to refresh the listview. – Raghunandan Nov 09 '12 at 04:00

2 Answers2

0

Check these links. Usually it is straing forward. Just create a Textwatcher and bind the adapter to the text changed. Or you can also implement the filterable interface and say android:textFilterEnabled is true.

link 1

link 2

Community
  • 1
  • 1
san
  • 1,845
  • 13
  • 23
0

This is because. you need to let the ListView know that a change in your data has occurred. To notify the ListView about the change, you need to call:

simpleAdapter.notifyDataSetChanged();

If for some reason it didn't work, you can also reassign the adapter of your ListView:

simpleAdapter = new SimpleAdapter(...);
lv.setAdapter(yourAdapter);
simpleAdapter.notifyDataSetChanged();
Arci
  • 6,647
  • 20
  • 70
  • 98