質問

I have a class that extends BaseExpandableListAdapter :

public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
        View convertView, ViewGroup parent) {
    Filter filter = (Filter) getChild(groupPosition, childPosition);
    if (convertView == null) {
        LayoutInflater infalInflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater.inflate(R.layout.exp_list_child, null);
    }
    TextView tv = (TextView) convertView.findViewById(R.id.child_tv);
    tv.setText(filter.toString());



    tv = (TextView) convertView.findViewById(R.id.child_sub_tv);
    tv.setText(filter.getType());

    if(!filter.getType().endsWith("ExportPin"))
        // I dont want to return antyhing

    return convertView;
}

As you can see I create a TextView and everything but I don't want to return it if the type of the filter does not end with "ExportPin" (see if statement at the end).

I can't return null and I dont want to return an empty list item.

In my class I also have getChildrenCount(), getGroupCount() ...

Any ideas?

役に立ちましたか?

解決

According to the official documentation, an Adapter should not be in charge of filtering the data :

An Adapter object acts as a bridge between an AdapterView and the underlying data for that view. The Adapter provides access to the data items. The Adapter is also responsible for making a View for each item in the data set.

You have to filter your data before putting them in your Cursor, then the Adapter will render the needed view to be display the data inside the ListView

他のヒント

Perhaps you should filter the data before passing it to the adapter, (or in adapter constructor) so that the adapter to use only the filtered already data.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top