3

我想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;
    }
}
4

1 回答 1

1

我自己对 Android 的这一部分不太了解,因为我很新,但我确实在我的研究中看到了关于 CursorTreeAdapter 的另一个问题。它内置了一些用于过滤的方法。这是有关它的Android API信息。CursorTreeAdapter 可以与 ExpandableListView 一起使用。

http://developer.android.com/reference/android/widget/CursorTreeAdapter.html

于 2014-12-16T00:09:43.840 回答