gpt4 book ai didi

android - 没有 child 的可扩展 ListView

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:26:03 28 4
gpt4 key购买 nike

我是 android 开发新手,也是第一次使用可扩展 ListView 。我正在创建一个应用程序,在其中我从 web 服务获取 d 可扩展 ListView 的所有内容。我也从 wevservice 获取所有内容但是当可扩展 ListView 中没有父项的子项时,可扩展 ListView getchildcount () 的自定义适配器 merhod 返回 null 并给出空指针异常我如何才能在列表中显示父项没有 child ,当两者都可用时?

谢谢

public View getChildView(int p_id, int c_id, boolean bln1, View view,ViewGroup viewgroup) {
// TODO Auto-generated method stub

if (view == null) {
view = inflater.inflate(com.example.eventlive.R.layout.homescreen_list_item_child, viewgroup,false);
}

TextView textView = (TextView) view.findViewById(R.id.list_item_text_child);
//"i" is the position of the parent/group in the list and
//"i1" is the position of the child
textView.setText(mParent.get(p_id).getArrayChildren().get(c_id));
view.setBackgroundResource(R.drawable.child_bg);
//return the entire view
return view;
}

//counts the number of children items so the list knows how many times calls getChildView() method
@Override
public int getChildrenCount(int p_id) {
// TODO Auto-generated method stub
return mParent.get(p_id).getArrayChildren().size();
}

最佳答案

像这样初始化一个空的子数组:

private HashMap<String, ArrayList<String>> mGroupsItems =
new HashMap<String, ArrayList<String>>();
. . .
mGroupsItems.put(name_of_empty_group, new ArrayList<String>());

关于android - 没有 child 的可扩展 ListView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16153154/

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