2013-02-21 76 views
1

我正在使用使用字符串數組列表的AutocompleteTextView。我的要求是,我需要與arraylist匹配的字符串數與輸入到AutocompleteTextView小部件中的字符數匹配。 請建議如何實現此功能。有關自動完成TextView的查詢

問候, 維傑

回答

1

好了,你手中有一個ArrayList中,你可以搜索與輸入的字母開頭的單詞。使用以下方法。

autocompletetextview.addTextChangedListener(new TextWatcher() { 

      @Override 
      public void onTextChanged(CharSequence s, int start, int before, int count) { 
       // TODO Auto-generated method stub 

      } 

      @Override 
      public void beforeTextChanged(CharSequence s, int start, int count, 
        int after) { 
       // set count to zero here 

      } 

      @Override 
      public void afterTextChanged(Editable s) { 

       // Do your search here 

      } 
     }); 

當您在視圖中鍵入內容時,您會看到參數's'中的文本。然後對ArrayList的每個元素使用element.startsWith(s)。如果爲true,則增加計數。