android - BaseExpandableListAdapter 返回特定的 Child,而不是全部

标签 android view return-value expandablelistadapter

我有一个扩展 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;
}

如您所见,我创建了一个 TextView 和所有内容,但如果过滤器的类型不以“ExportPin”结尾,我不想返回它(看看最后的 if 语句)。

我不能返回 null 并且我不想返回空列表项。

在我的课上我还有 getChildrenCount(), getGroupCount() ...

有什么想法吗?

最佳答案

根据official documentation , Adapter 不应该负责过滤数据:

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.

在将数据放入 Cursor 之前,您必须过滤数据,然后 Adapter 将呈现所需的 View 以在 ListView< 中显示数据

关于android - BaseExpandableListAdapter 返回特定的 Child,而不是全部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16912181/

相关文章:

Android 4.4 虚拟设备内部存储不会调整大小

android - 需要在根 SD 卡中找到 .txt 文件的位置

sorting - 订购 Backbone View 和集合

c# - 如何从 WCF 服务返回 LINQ to SQL 表实体?

c++ - 在 R 脚本中使用 C++ 程序的返回值

android - Lazy List 上的位图缓存(SoftReference,Hard)似乎无法正常工作 - Android

Android:从顶部开始循环进度条(270°)

android - 动态计算 View 元素的大小

xcode - 在 Xcode 4.3 中添加自定义对象

c - 函数调用后指针返回值改变