简体   繁体   中英

unable to refresh data in listview

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);

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

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM