我希望在 Android 的 ExpandableListView
中使用 EditText
过滤数据,确认 adapter
应该实现 Filtering
,但由于缺乏关于筛选数据的知识,不知道如何实现这个功能。我的适配器结构如下:
public class ExpandableListAdapter extends
BaseExpandableListAdapter /*implements Filterable*/ {
private final Context myContext;
private String[] arrayTopics;
private String[][] arraySubTopics;
public PrimeirosSOSExpandableListAdapter(Context context) {
this.myContext = context;
}
public ExpandableListAdapter(Context context,
String[] arrayTopics, String[][] arraySubTopics) {
this.myContext = context;
this.arrayTopics = arrayTopics;
this.arraySubTopics = arraySubTopics;
}
public Object getChild(int groupPosition, int childPosition) {
return null;
}
public long getChildId(int groupPosition, int childPosition) {
return 0;
}
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) myContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.child_layout,
null);
}
TextView tv = (TextView) convertView.findViewById(R.id.tvChild);
tv.setText(arraySubTopics[groupPosition][childPosition]);
return convertView;
}
public int getChildrenCount(int groupPosition) {
return arraySubTopics[groupPosition].length;
}
public Object getGroup(int groupPosition) {
return null;
}
public int getGroupCount() {
return arrayTopics.length;
}
public long getGroupId(int groupPosition) {
return 0;
}
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) myContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.group_layout,
null);
}
TextView tv = (TextView) convertView.findViewById(R.id.tvGroup);
tv.setText(arrayTopics[groupPosition]);
return convertView;
}
public boolean hasStableIds() {
return false;
}
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}