久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

從編輯文本中過濾列表視圖

Filter list view from edit text(從編輯文本中過濾列表視圖)
本文介紹了從編輯文本中過濾列表視圖的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時(shí)送ChatGPT賬號..

我有一個(gè)作為搜索欄的編輯文本和一個(gè)過濾我輸入的文本的列表視圖,但不幸的是,它不會(huì)過濾列表視圖.我使用了帶有對象 Friend 的自定義數(shù)組適配器.朋友對象有名字、地址和電話號碼,但我只想過濾它的名字.在我的活動(dòng)中...

searchBarTextView.addTextChangedListener(new TextWatcher() {@覆蓋public void onTextChanged(CharSequence s, int start, int before, int count) {friendListAdapter.getFilter().filter(s);}}

在適配器中...

<前>@覆蓋公共過濾器getFilter(){Log.d(TAG, "開始 getFilter");if(newFilter == null) {新過濾器 = 新過濾器() {@覆蓋protected void publishResults(CharSequence 約束,F(xiàn)ilterResults 結(jié)果) {//TODO 自動(dòng)生成的方法存根Log.d(TAG, "發(fā)布結(jié)果");notifyDataSetChanged();}

<代碼> @Override受保護(hù)的FilterResults performFiltering(CharSequence約束){Log.d(TAG, "執(zhí)行過濾");約束 = 約束.toString().toLowerCase();Log.d(TAG, "約束:"+約束);列出<ChatObject>filtersFriendList = new LinkedList();for(int i=0; i

有人可以幫我如何正確顯示過濾后的數(shù)組適配器嗎?我認(rèn)為 notifyDataSetChanged 沒有被調(diào)用.謝謝.

解決方案

我的問題解決了,發(fā)現(xiàn)我要重寫 getCount()getItem().

I have an edit text as a search bar and a list view that filters the text that I typed but unfortunately, it doesn't filter the list view. I have used an customize array adapter with object Friend. Friend object has name, address and phone number but I only want to filter its name. In my activity...

searchBarTextView.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
    friendListAdapter.getFilter().filter(s);
}}

While in adapter...

    @Override
    public Filter getFilter() {
        Log.d(TAG, "begin getFilter");
        if(newFilter == null) {
            newFilter = new Filter() {
                @Override
                protected void publishResults(CharSequence constraint, FilterResults results) {
                    // TODO Auto-generated method stub
                    Log.d(TAG, "publishResults");
                    notifyDataSetChanged();
                }

@Override protected FilterResults performFiltering(CharSequence constraint) { Log.d(TAG, "performFiltering"); constraint = constraint.toString().toLowerCase(); Log.d(TAG, "constraint : "+constraint); List<ChatObject> filteredFriendList = new LinkedList<ChatObject>(); for(int i=0; i<friendList.size(); i++) { Friend newFriend = friendList.get(i); Log.d(TAG, "displayName : "+newFriend.getDisplayName().toLowerCase()); if(newFriend.getDisplayName().toLowerCase().contains(constraint)) { Log.d(TAG, "equals : "+newFriend.getDisplayName()); filteredFriendList.add(newFriend); } } FilterResults newFilterResults = new FilterResults(); newFilterResults.count = filteredFriendList.size(); newFilterResults.values = filteredFriendList; return newFilterResults; } }; } Log.d(TAG, "end getFilter"); return newFilter; }

Could someone please help me how to correctly show the filtered array adapter? I think the notifyDataSetChanged is not invoked. Thanks.

解決方案

My problem is solved, found out that I have to override getCount() and getItem().

這篇關(guān)于從編輯文本中過濾列表視圖的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Cut, copy, paste in android(在android中剪切、復(fù)制、粘貼)
android EditText blends into background(android EditText 融入背景)
Change Line Color of EditText - Android(更改 EditText 的線條顏色 - Android)
EditText showing numbers with 2 decimals at all times(EditText 始終顯示帶 2 位小數(shù)的數(shù)字)
Changing where cursor starts in an expanded EditText(更改光標(biāo)在展開的 EditText 中的開始位置)
EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView問題)
主站蜘蛛池模板: 国产在线一区二区三区 | 成人高清视频在线观看 | 免费爱爱视频 | 观看av | 午夜av一区二区 | 久久精品一| 一区二区三区小视频 | 国产黄色av网站 | 日日夜夜精品视频 | 亚洲国产高清免费 | 美女福利视频一区 | 91免费视频 | 91麻豆精品国产91久久久更新资源速度超快 | 亚洲综合网站 | 别c我啊嗯国产av一毛片 | 成年人在线视频 | 四虎伊人 | 国产欧美在线视频 | 最新一级毛片 | 一区二区av | www.亚洲国产精品 | 天天久久 | 一呦二呦三呦国产精品 | 91精品国产欧美一区二区成人 | 日韩在线免费 | 波多野结衣中文字幕一区二区三区 | 国产精品一级 | 在线高清免费观看视频 | 中文字幕在线一区 | 午夜一区二区三区在线观看 | 日韩精品一区二区三区在线观看 | 欧美一级小视频 | 国产精品高清在线 | 成人在线中文字幕 | 久草综合在线 | 亚洲一区国产精品 | 奇米视频777| 日韩综合在线 | 国产精品精品久久久 | 国产一区二区三区四区 | 国产精品中文 |