gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 21:41:36 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com