我有以下片段,它显示一个自定义的listiview,其中每行有2个项目。日语作品,意思是葡萄牙语。我正在尝试实施一个searh吧。栏显示,但我不知道如何搜索和过滤列表
真实的清单,如果比这长得多。我知道我应该在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);
}
//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);
}
答案 0 :(得分:0)
我通过使用活动而不是片段解决了这个问题。以下代码工作正常: