我真的需要一些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