2016-11-07 98 views
1

我想爲@創建自定義分詞器像whatspp功能(當打開組和寫@然後打開彈出列表和用戶可以選擇any.also用戶可以刪除該字符串@ 。Android MultiAutoCompleteTextView自定義分詞器就像whatsapp GroupChat

我搜索很多事情。可是我已經找到像Twitter的搜索功能Example like twitter

但在這一點,當用戶可以寫@那麼不顯示列表的彈出窗口。用戶可以後@寫soemthing然後根據打字,彈出窗口將顯示搜索結果。

我想要顯示這樣的方法:

感謝先進。

enter image description here

+0

http://stackoverflow.com/a/18486927/3850595 –

+0

[檢查此鏈接](https://android-arsenal.com/tag/197),大量的例如可用.. [最好的一個](https://android-arsenal.com/details/1/2953) –

+0

@NiranjPatel我想添加@並打開與autocompletetext視圖相同的自定義列表彈出窗口。 – dipali

回答

0

我得到了我的問題的解決方案。

我已爲multiautocompletetextview創建了自己的自定義視圖,並在@sign之後爲打開的彈出框添加了performFiltering方法。

public class KcsMultiAutoCompleteTextView extends MultiAutoCompleteTextView { 
    public KcsMultiAutoCompleteTextView(Context context) { 
     super(context); 
    } 

    public KcsMultiAutoCompleteTextView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 

    public KcsMultiAutoCompleteTextView(Context context, AttributeSet attrs, int defStyleAttr) { 
     super(context, attrs, defStyleAttr); 
    } 

    @Override 
    protected void performFiltering(CharSequence text, int start, int end, int keyCode) { 
     if (text.charAt(start) == '@') { 
      start = start + 1; 
     } else { 
      text = text.subSequence(0, start); 
      for (int i = start; i < end; i++) { 
       text = text + "*"; 
      } 
     } 
     super.performFiltering(text, start, end, keyCode); 
    } 

} 
+0

嗨@dipali ....可以解釋我們如何在每次使用此自定義類編寫@時在API中從運行時獲取列表? –

+0

@MohammadMisbah只需使用此自定義類並設置textview,然後它將在自定義類arraylist中執行過濾器。 – dipali