我想在 listview 中创建搜索功能,我有点怀疑使用 arraylist 是否可以执行搜索功能。这里我附上了代码..
Totalarraylist 是数组列表,我从该数组列表将数据传递给问题适配器类代码,
searchbox.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
// When user changed the Text
If so then what to add here for search functionality...
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
adapterfirst = new Questionadapter(MainActivity.this,Totalarraylist);
listviewfirst = (ListView) findViewById(R.id.listquestion);
listviewfirst.setAdapter(adapterfirst);
}
public class Questionadapter extends BaseAdapter {
private ArrayList<HashMap<String, Object>> data;
public LayoutInflater inflater;
Context context;
public Questionadapter(Context context, ArrayList<HashMap<String,Object>> Totalarraylists) {
// TODO Auto-generated constructor stub
data=Totalarraylists;
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
System.out.println("data="+data);
}
public int getCount() {
return data.size();
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
public View getView(int position, View convertView, ViewGroup parent) {
//
}
}
任何人都可以帮我做到这一点..