How to make ListView filter on Android

…衆ロ難τιáo~ 提交于 2019-12-06 08:02:28

The problem is that the adapter variable is not the same ArrayAdapter that you use in SetListAdapter().

Try using this code in the OnCreate() method:

this.adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mStrings);
setListAdapter(adapter);

Rather you can do the same in one line

setListAdapter(adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, mStrings));

Cheers!

rahul dr

You should use the statement:

 adapter.notifyDataSetChanged();

to update the adapter after filtering the ListView items. Only then you can see the filtered results.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!