0
我有以下片段,它顯示一個自定義listiview,其中每行都有2個項目。日語作品及其在葡萄牙語中的意義我正在嘗試實施一個搜索欄。酒吧顯示,但我不知道如何搜索和篩選列表在Android片段上實現搜索
真實的列表,如果比這更長。我知道我應該已經在xml中實現了這個列表,但這樣做更簡單。
public class Dicionario extends ListFragment {
//ArrayList holds the data (as HashMaps) to load into the ListView
ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();
//SimpleAdapter does the work to load the data in to the ListView
private SimpleAdapter sa;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_dicionario, container,
false);
((MainActivity) getActivity()).setActionBarTitle(getString(R.string.dicionariotitle));
Arrays.sort(termos, new ColumnComparator(0));
HashMap<String,String> item;
for(int i = 0; i< termos.length; i++){
item = new HashMap<String,String>();
item.put("line1", termos[i][0]);
item.put("line2", termos[i][1]);
list.add(item);
}
sa = new SimpleAdapter(getActivity().getApplicationContext(), list, R.layout.my_two_lines, new String[] { "line1","line2" }, new int[] {R.id.line_a, R.id.line_b});
setListAdapter(sa);
return rootView;
//setListShown(true);
}
private String[][] termos =
{{"DOJÔ","Área de Treinamento"},
{"JÔ-SEKI","Lugar onde se sentam as autoridades"},
{"REI-HÔ","Saudação"},
{"REI","Cumprimento"},
{"MOKUSO","Meditação (Fechar os olhos e manter silêncio)"},
{"ZA-REI","Cumprimento ajoelhado"},
{"RITSU-REI","Cumprimento em pé"},
{"SHI-HAN","Mestre"},
{"SENSEI","Professor"},
{"SEITÔ","Aluno"},
{"DÔO-HAI","Colegas"},
{"NINTAI","Perserverança"},
{"DORYOKU","Esforço, empenho"},
{"HISSHYÔ","Ei de vencer"},
{"KATANÁ","Espada"},
{"DAITÔO","Espada Maior"},
{"SHÔOTÔO","Espada Menor"},
{"TANTÔO","Punhal"},
{"BOKKEN","Espada de Madeira"}
};
@Override
public void onDestroyView() {
super.onDestroyView();
ButterKnife.reset(this);
}
}