我真的需要一些SearchView和我的列表视图与自定义列表项的帮助。我认为我的活动班编码好,但我真的不知道该怎么办在我的适配器..Android Searchview for listview - >如何修改适配器
我会把活动类的代码,如果需要.. 这是我现在的适配器:
public class List_message extends BaseAdapter implements Filterable {
private Context context;
private List<String> sender;
private List<String> type;
private LayoutInflater inflater;
public List_message(Context context,List<String> sender,List<String> type) {
inflater = LayoutInflater.from(context);
this.context = context;
this.sender = sender;
this.type = type;
}
public int getCount() {
return sender.size();
}
public Object getItem(int position) {
return sender.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(final int position, View convertView, ViewGroup parent) {
String sender_tekst = sender.get(position);
String type_tekst = type.get(position);
View v = null;
if(convertView != null)
v = convertView;
else
v = inflater.inflate(R.layout.vrstica_private_message, parent, false);
TextView posiljatelj = (TextView)v.findViewById(R.id.message_sender);
posiljatelj.setText(sender_tekst);
TextView type = (TextView)v.findViewById(R.id.message_writer);
type.setText(type_tekst);
ImageButton button = (ImageButton)v.findViewById(R.id.message_delete);
button.setOnClickListener(
new OnClickListener() {
public void onClick(View v) {
}
});
return v;
}
public Filter getFilter() {
return null;
}
}
只需重新设置'列表 sender'的过滤列表并在适配器上执行notifyDataSetChanged。这样,不需要更改适配器。不要忘记备份发件人的完整列表和过滤器列表 –
Jivy
2014-12-05 14:11:14
好的,我如何重新设置列表发件人的过滤列表? 我应该仅备份发件人的列表,而不是过滤的列表,因为随时搜索视图正在使用的过滤器会被更改吗? –
DJack
2014-12-05 14:19:30
我结束我在这里找到了答案: http://stackoverflow.com/questions/23422072/searchview-in-listview-having-a-custom-adapter – DJack 2014-12-08 19:55:47