2012-03-14 20 views
0

私はリストを持ち、各行はメインアイテムとサブアイテムで構成されています。私はユーザーが検索edittextに入力すると、リストを更新するフィルタを使用しています。 入力時に、リスト内の項目は入力されたアルファベットに従って表示されますが、各項目は2回表示されます。以下 は私のコードです:ListViewはフィルタリング後に各項目を2回表示します

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()もサブアイテムテキストをフィルタリングしていたため、各項目を2回追加していました。

関連する問題