【发布时间】:2014-12-05 13:57:39
【问题描述】:
我真的需要一些关于 SearchView 和我的带有自定义列表项的列表视图的帮助。我认为我的活动类编码正常,但我真的不知道在我的适配器中做什么..
如果需要,我会放上 Activity 类的代码.. 这是我现在的适配器:
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;
}
}
【问题讨论】:
-
只需重新设置
List<String> sender的过滤列表并在您的适配器上执行 notifyDataSetChanged。这样,无需更改适配器。不要忘记备份发件人的完整列表和过滤的发件人列表 -
好的,如何重新设置 List
发件人的过滤列表?我应该只备份发件人列表而不是过滤的列表,因为过滤的列表会在搜索视图使用时发生变化,对吗? -
我终于在这里找到了答案:stackoverflow.com/questions/23422072/…
标签: android listview adapter searchview