2016-03-02 88 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接受它作为一个有用的答案:) –