2016-03-02 191 views
0

中輸入第一個字母本身時未顯示的人建議列表在我們輸入第一個字母本身期間未顯示的用戶建議列表中。在搜索欄中輸入第二個字母后,建議將顯示。任何人都會給出此question.`可能的解決方案在我們在android

search.addTextChangedListener(new TextWatcher() { 
      @Override 
      public void beforeTextChanged(CharSequence s, int start, int count, int after) { 

      } 

      @Override 
      public void onTextChanged(CharSequence s, int start, int before, int count) { 
       adapter.getFilter().filter(s, new Filter.FilterListener() { 
        public void onFilterComplete(int count) { 
         Log.d("log", "result count:" + count); 
         if (count == 0) { 
          usermsg.setText("No username found"); 
          usermsg.setVisibility(View.VISIBLE); 
          peoplelist.setVisibility(View.GONE); 
         } else { 
          usermsg.setVisibility(View.GONE); 
          peoplelist.setVisibility(View.VISIBLE); 

         } 
        } 
       }); 
      } 

      @Override 
      public void afterTextChanged(final Editable s) { 

       adapter.getFilter().filter(s, new Filter.FilterListener() { 
        public void onFilterComplete(int count) { 
         Log.d("log", "result count:" + count); 
         if (text.equals("people")) { 
          //movieList.clear(); 
          getPeople(); 
          if (count == 0) { 
           usermsg.setText("No username found"); 
           usermsg.setVisibility(View.VISIBLE); 
           peoplelist.setVisibility(View.GONE); 
          } else { 
           usermsg.setVisibility(View.GONE); 
           peoplelist.setVisibility(View.VISIBLE); 
          } 
         } else if (text.equals("tag")) { 
          getTag(s); 
           usermsg.setText("# No Hash Tag found"); 
           usermsg.setVisibility(View.VISIBLE); 
           peoplelist.setVisibility(View.GONE); 
          /*else { 
           usermsg.setVisibility(View.GONE); 
           peoplelist.setVisibility(View.VISIBLE); 
          }*/ 
         } 
        } 
       }); 
      } 
     });` 
+0

在你onTextChanged或afterTextChanged您可以執行opertion你爲什麼要執行操作的addTextChangedListener方法的兩個方法的編輯文本... –

+0

我可以做什麼來顯示人名單,同時在編輯文本框中鍵入第一個字母 – suriya

+0

你必須維護到arraylist ...一個是所有的數據,另一個是來自過濾器的最短數據。 ... –

回答

0

你要維持兩個ARRAYLIST,一個爲你的所有數據ListView,另一個用於過濾數據...

所以在我下面的解決方案我有兩個ArrayList一個是所有名稱爲FUL的數據L_DATA_ARRAYLIST,另一個用於FILTER_ARRAYLIST,所以PLZ是指下面的解決方案是: -

 search.addTextChangedListener(new TextWatcher() { 
      @Override 
      public void beforeTextChanged(CharSequence s, int start, int count, int after) { 

      } 

      @Override 
      public void onTextChanged(CharSequence s, int start, int before, int count) { 
       if (s.toString().length() == 0) { 

        usermsg.setText("No username found"); 
        usermsg.setVisibility(View.VISIBLE); 



        adapter = new YOURADAPTERCLASS(YOUR_ACTIVITY.this, FULL_DATA_ARRAYLIST); 
        peoplelist.setAdapter(adapter); 
       } else { 

         usermsg.setVisibility(View.GONE); 
         peoplelist.setVisibility(View.VISIBLE); 


        FILTER_ARRAYLIST.clear(); 
        for (int i = 0; i < FULL_DATA_ARRAYLIST.size(); i++) { 
         if (FULL_DATA_ARRAYLIST.get(i).getName().toLowerCase().contains(s.toString().toLowerCase())) 
          FILTER_ARRAYLIST.add(FULL_DATA_ARRAYLIST.get(i)); 
        } 
        adapter = new YOURADAPTERCLASS(YOUR_ACTIVITY.this, FILTER_ARRAYLIST); 
        peoplelist.setAdapter(adapter); 
       } 

      } 

      @Override 
      public void afterTextChanged(Editable s) { 

      } 
     }); 
+0

如何創建一個過濾器數組列表 – suriya

+0

ArrayList FILTER_ARRAYLIST = new ArrayList ; –

+0

@suriya ..對你有幫助嗎,比PLZ接受它作爲一個有用的答案:) –