How to use getFilter form Listadapter

泪湿孤枕 提交于 2019-12-11 01:49:33

问题


I try to filter in Listview where the adapter is ListAdapter, I couldn't find getFilter() , Is there any work around? Below is my code.

// Adding menuItems to ListView
            final ListAdapter adapter = new SimpleAdapter(this, songsListData,
                    R.layout.playlist_item, new String[]{"songTitle"}, new int[]{
                    R.id.songTitle});

            setListAdapter(adapter);

            sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
                @Override
                public boolean onQueryTextSubmit(String query) {
                    return false;
                }

                @Override
                public boolean onQueryTextChange(String newText) {
                    //adapter.getFilter
                    return false;
                }
            });

回答1:


I find myself, It's simple.

final SimpleAdapter adapter = new SimpleAdapter(this, songsListData,
                    R.layout.playlist_item, new String[]{"songTitle"}, new int[]{
                    R.id.songTitle});

    sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
                @Override
                public boolean onQueryTextSubmit(String query) {
                    return false;
                }

                @Override
                public boolean onQueryTextChange(String newText) {
                    adapter.getFilter().filter(newText);
                    return false;
                }
            });


来源:https://stackoverflow.com/questions/35417010/how-to-use-getfilter-form-listadapter

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