Victor CS
Victor CS

Reputation: 71

ExpandableListView Android + filter EditText

I would like to filter the data in a ExpandableListView in android using EditText, verify that the adapter should implement Filtering but do not know how to accomplish this implementation due to lack of knowledge on filter data. The structure of my adapter is:

    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;
    }
}

Upvotes: 3

Views: 1036

Answers (1)

Michael Garner
Michael Garner

Reputation: 1092

I don't know too much about this part of Android myself as I am quite new, but I did see in my research for another problem some stuff about the CursorTreeAdapter. It has some methods built into it to work with filtering. Here is the Android API information about it. The CursorTreeAdapter can be used with an ExpandableListView.

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

Upvotes: 1

Related Questions