2012-08-09 69 views
0

嗨在我的应用程序中有一个列表视图和一个搜索部分。我需要做的是当我在搜索部分搜索一个单词时,它应该根据我搜索的单词列出相应的列表视图。排序的名字,但我真正的问题代码,如果我需要寻找比如我需要搜索在我们的应用程序在Android搜索列表?

Ramz超级

这是一个单一的名字在我当前的代码,我需要一个字搜索从R然后A等按正确的顺序排序的名称。但我需要的是,如果我开始搜索超级我需要显示n AME Ramz在listview.how超级我能做到这一点我现在的搜索代码如下所示

search_sort.addTextChangedListener(new TextWatcher() { 
     public void afterTextChanged(Editable s) { 
      // Abstract Method of TextWatcher Interface. 
     } 

     public void beforeTextChanged(CharSequence s, int start, int count, 
       int after) { 
      // Abstract Method of TextWatcher Interface. 
     } 

     public void onTextChanged(CharSequence s, int start, int before, 
       int count) { 
      textlength = search_sort.getText().length(); 
      array_sort.clear(); 
      contactnumber_sort.clear(); 
      for (int i = 0; i < contactname.size(); i++) { 
       if (textlength <= contactname.get(i).length()) { 
        if (search_sort.getText() 
          .toString() 
          .equalsIgnoreCase(
            (String) contactname.get(i).subSequence(
              0, textlength))) { 
         array_sort.add(contactname.get(i)); 
         contactnumber_sort.add(contactnumber.get(i)); 
        } 
       } 
      } 
      System.out.println(array_sort); 

      myadp = new myAdapter(MobiMailActivity.this, array_sort, contactnumber_sort); 
      contactlist.setAdapter(myadp); 
     } 
    }); 
+0

看一看这个http://stackoverflow.com/questions/11823720 – Braj 2012-08-09 08:57:05

回答

1

尝试使用而不是equalsIgnoreCase()。哪里datasetList是我的自定义ArrayList<ContactList>的对象。

public void onTextChanged(CharSequence s, int start, int before, int count) { 
     // TODO Auto-generated method stub 
     String getSearchString = search.getText().toString(); 

     if(datasetList != null && datasetList.size() > 0) 
     { 
      sortedList = new ArrayList<ContactDataSet>(); //new List sorted list 

      for (int i = 0; i < datasetList.size(); i++) { 

       if (datasetList.get(i).getName().contains(getSearchString)) { 
        sortedList.add(datasetList.get(i)); 

       } 
      } 
     }   
     adapter.setnewList(sortedList); 
     lView.setAdapter(adapter); 

    } 

试试这个,让我know.It是me.Hope工作这可以帮助你

+0

当我使用它没有得到任何值 – Ramz 2012-08-09 08:29:31

+0

@Ramz我已更新我的代码看看,让我知道。 – Akshay 2012-08-09 08:41:09

+0

还没有列出任何值:( – Ramz 2012-08-09 08:46:11

相关问题