2012-03-14 4 views
0

각 항목에는 기본 항목과 하위 항목으로 구성된 목록이 있습니다. 사용자가 검색 edittext에 입력 할 때 필터를 사용하여 목록을 새로 고칩니다. 입력시 목록에있는 항목이 입력 된 영문자에 따라 표시되지만 각 항목은 두 번 표시됩니다.ListView는 필터링 후 각 항목을 두 번 표시합니다.

public class NewReqFragment extends ListFragment 
{ 
     ListView newReqList; 
    LayoutInflater inflater; 
    String[] from = new String[] {"mainrow", "subrow"}; 
    EditText searchBar = null; 
    SimpleAdapter sAdapter =null; 

    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState);    
    } 

    public void onActivityCreated(Bundle savedInstanceState) 
     { 
      super.onActivityCreated(savedInstanceState); 

      newReqList = this.getListView(); 

      searchBar = (EditText)this.getActivity().findViewById(R.id.searchbar); 

      List<HashMap<String, String>> fillMaps = new ArrayList<HashMap<String, String>>(); 
      for(int i = 0; i < ListItemStrings.NEWREQTITLES.length; i++) 
      { 
       HashMap<String, String> map = new HashMap<String, String>(); 
       map.put("mainrow",ListItemStrings.NEWREQTITLES[i]); 
       map.put("subrow",ListItemStrings.NEWREQCHILDLIST[i]); 
       fillMaps.add(map); 
       }   



      sAdapter = new SimpleAdapter (this.getActivity(), fillMaps 
        , R.layout.simple_list_item_checkable_1, 
        from, new int[] {R.id.text1, R.id.text2}); 
      newReqList.setAdapter(sAdapter); 
      searchBar.addTextChangedListener(filterTextWatcher); 
    } 

    private TextWatcher filterTextWatcher = new TextWatcher() 
    { 

     public void afterTextChanged(Editable s) 
     { 
     } 

     public void beforeTextChanged(CharSequence s, int start, int count, 
       int after) 
     { 
     } 

     public void onTextChanged(CharSequence s, int start, int before, 
       int count) 
     { 
      sAdapter.getFilter().filter(s); 
      sAdapter.notifyDataSetChanged();   
     } 


    }; 

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
    { 
     View v = inflater.inflate(R.layout.newreqscrlayout, container,false); 
     return v; 
    }   
} 

사람이 무엇이 잘못되었는지를 찾아 좀 도와 주시겠습니까 : 아래 내 코드?

답변

0

사용자 지정 SimpleAdapter를 만들어 해결했습니다.
내 목록은 Item과 Subitem으로 구성됩니다. SimpleAdapter 메서드 performFiltering()은 하위 항목 텍스트도 필터링하여 각 항목을 두 번 추가했습니다. 루프를 실행하면 한 번만 결과가 나타납니다.

관련 문제