2016-06-27 86 views
0

我在搜索專業和學校時使用autocompleteTextview。在我的自動完成textbox返回搜索查詢的實際串像選擇結果後AutoCompleteTextView返回模型

major = Computer Science 
schools = Harvard University 

但點擊返回像

模型所選擇的項目後,這是我的過濾器的代碼在我校適配器

@Override 
public Filter getFilter() { 
    Filter filter = new Filter() { 
     @Override 
     protected FilterResults performFiltering(CharSequence constraint) { 
      FilterResults filterResults = new FilterResults(); 
      if(constraint != null){ 
       List<MTSSchool> filterValue = new ArrayList<MTSSchool>(); 

       for(int x = 0; x < _filtteredSchoolList.size(); x++){ 
        if(_filtteredSchoolList.get(x).getSchool_name().contains(constraint)){ 
         MTSSchool university = new MTSSchool(_filtteredSchoolList.get(x).getSchool_name(),_filtteredSchoolList.get(x).getSchoolId()); 
         filterValue.add(university); 
        } 
       } 

       filterResults.values = filterValue; 
       filterResults.count = filterValue.size(); 
      } 
      return filterResults; 
     } 

     @Override 
     protected void publishResults(CharSequence constraint, FilterResults results) { 
      if(results != null && results.count > 0){ 
       _filtteredSchoolList = (List<MTSSchool>)results.values; 
       notifyDataSetChanged(); 
      }else { 
       notifyDataSetInvalidated(); 
      } 
     } 
    }; 
    return filter; 
} 

    protected void publishResults(CharSequence constraint, FilterResults results) { 
      if(results != null && results.count > 0){ 
       _filtteredSchoolList = (List<MTSSchool>)results.values; 
       notifyDataSetChanged(); 
      }else { 
       notifyDataSetInvalidated(); 
      } 
     } 

enter image description here

選擇選項後在自動完成這是輸出

我注意到我的3 autocompleteTextview它不會重置搜索結果,但它限制了其他自動完成任何建議這傢伙?

回答

1

對於MTSSchool類實現toString()方法,它返回學校的名字

+0

公共字符串的ToString(){ 回報school_name; }這就是我加入的那個測試吧 –

+0

這裏發佈日誌。 – Sush

+0

https://shrib.com/ITH4ra8qnSGyvIU請檢查網站 –