【问题标题】:BaseExpandableListAdapter return sepcific Child, not all of themBaseExpandableListAdapter 返回特定的 Child,而不是全部
【发布时间】:2013-05-30 12:22:11
【问题描述】:

我有一个扩展 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() ...

有什么想法吗?

【问题讨论】:

    标签: android view return-value expandablelistadapter


    【解决方案1】:

    根据official documentationAdapter 不应该负责过滤数据:

    适配器对象充当适配器视图和该视图的基础数据之间的桥梁。适配器提供对数据项的访问。 Adapter 还负责为数据集中的每一项创建一个 View。

    您必须在将数据放入您的Cursor 之前对其进行过滤,然后Adapter 将呈现所需的视图以在ListView 中显示数据

    【讨论】:

    • 感谢您的回答。我通过 URI 将它们放在光标中,那我该怎么做呢?
    • 你的URI应该过滤你的数据,或者你应该自己做过滤过程(循环游标中的项目或其他东西)。在 BaseExpandableListAdapter 的构造函数中或在实例化 Cursor 时执行此操作。
    • 如果您现在一切正常,请不要忘记接受、投票等... ;)
    • 是的,别担心,我一拿到就做 :) 我仍然卡住了,但它会起作用的!
    【解决方案2】:

    也许您应该在将数据传递给适配器之前(或在适配器构造函数中)过滤数据,以便适配器仅使用已过滤的数据。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-17
      • 2018-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多