0

これは、メインアクティビティクラスのものです。私は配列のarraylistがあり、リストビューの検索バーを作成する必要があります。アンドロイドスタジオでカスタムリストビューを検索する方法を教えてください。

adapter = new ArrayAdapter<String[]>(this, R.layout.list_view, android.R.id.text1, spellList) 
    { 
     public View getView(int position, View convertView, ViewGroup parent) 
     { 
      View view = super.getView(position, convertView, parent); 

      String[] entry = spellList.get(position); 
      TextView text1 = (TextView) view.findViewById(android.R.id.text1); 
      TextView text2 = (TextView) view.findViewById(android.R.id.text2); 
      text1.setText(entry[0]); 
      text2.setText(entry[1]); 

      return view; 
     } 
    }; 
    wizList.setAdapter(adapter); 

    searchText.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) { 

     } 


     @Override 
     public void afterTextChanged(Editable s) { 

     } 
    }); 

これは文字列配列のArraylistのデータです。呪文名で検索された場合は優先されます。

final ArrayList<String[]> spellList; 

public WizardDatabase() 
{ 
    spellList = new ArrayList<>(); 

    spellList.add(new String[] { "Resistance", "Subject gains +1 on saving throws."}); 
    spellList.add(new String[] { "Acid Splash", "Orb deals 1d3 acid damage."}); 
    spellList.add(new String[] { "Detech Poison", "Detects poison in one creature or small object."}); 

public ArrayList<String[]> getList() 
{ 
    return spellList; 
} 

ありがとう。

答えて

0

それは、単純な文字列検索ならだけにしてフィルタは文字列配列の私のArrayListのために動作しません。次のコード

searchText.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) { 

     } 


     @Override 
     public void afterTextChanged(Editable s) { 
      if (s.length() > 3) { // it's for performance I've put 3 you can change it 
       adapter.getFilter().filter(s.toString()); 
      } 
     } 
    }); 
+0

を使用しています。それは主に問題がどこにあるのかです。 –

+0

@ GarryAlcorn次に独自のバージョンのフィルタを実装する必要があります –

+0

カスタムアダプタを作成する必要がありますか? –

関連する問題