我想ExpandableListView
在 android 中使用过滤数据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;
}
}