android– 从ExpandableListView的getChildView()访问groupview的TextView

android– 从ExpandableListView的getChildView()访问groupview的TextView,第1张

概述我正在尝试访问GroupView的textview,它显示ChildView中所选复选框的计数.例如 - North是GroupView,下面带有复选框的列表是ChildView.我想每次点击复选框更新计数(18).我在复选框上应用了OnClickListner.我有自定义ExpanadableListViewAdapter扩展BaseExpandable

我正在尝试访问GroupVIEw的textvIEw,它显示ChildVIEw中所选复选框的计数.

例如 – north是GroupVIEw,下面带有复选框的列表是ChildVIEw.我想每次点击复选框更新计数(18).我在复选框上应用了OnClickListner.我有自定义ExpanadableListVIEwAdapter扩展Baseexpandablelistadapter.

这是我的代码片段 –

@OverrIDepublic VIEw getGroupVIEw(int groupposition,boolean isExpanded,VIEw convertVIEw,VIEwGroup parent) {    if (convertVIEw == null) {        convertVIEw = LayoutInflater.from(parent.getContext()).inflate(R.layout.filter_expandable_List_group,parent,false);        groupVIEwHolder = new GroupVIEwHolder();        groupVIEwHolder.Groupname = (TextVIEw) convertVIEw.findVIEwByID(R.ID.group_name);        groupVIEwHolder.GroupCount = (TextVIEw) convertVIEw.findVIEwByID(R.ID.group_count);        groupVIEwHolder.rightArrow = (ImageVIEw) convertVIEw.findVIEwByID(R.ID.right_arrow);        convertVIEw.setTag(groupVIEwHolder);    }else{        groupVIEwHolder = (GroupVIEwHolder) convertVIEw.getTag();    }    groupVIEwHolder.Groupname.setText(((OutletListData) getGroup(groupposition)).getname());    groupVIEwHolder.GroupCount.setText(""+((OutletListData) getGroup(groupposition)).getoutletDatas().size());    return convertVIEw;}@OverrIDepublic VIEw getChildVIEw(final int groupposition,final int childposition,boolean isLastChild,final VIEwGroup parent) {    if (convertVIEw == null) {        convertVIEw = LayoutInflater.from(parent.getContext()).inflate(R.layout.filter_expandable_List_child,false);        childVIEwHolder = new ChildVIEwHolder();        childVIEwHolder.childTextVIEw = (TextVIEw) convertVIEw.findVIEwByID(R.ID.text1);        childVIEwHolder.childCheckBox = (CheckBox) convertVIEw.findVIEwByID(R.ID.checkBox);        convertVIEw.setTag(childVIEwHolder);    }else{        childVIEwHolder = (ChildVIEwHolder) convertVIEw.getTag();    }    childVIEwHolder.childTextVIEw.setText(((OutletData) getChild(groupposition,childposition)).getDealername());    childVIEwHolder.childCheckBox.setChecked(((OutletData) getChild(groupposition,childposition)).getSelected() == "1");    childVIEwHolder.childCheckBox.setonClickListener(new VIEw.OnClickListener() {        @OverrIDe        public voID onClick(VIEw v) {            boolean isChecked = ((CheckBox) v).isChecked();            ApplicationController.getEventBus().post(((OutletData) getChild(groupposition,childposition)).getoutletID());            if (isChecked) {                ((OutletData) getChild(groupposition,childposition)).setSelected("1");            } else {                ((OutletData) getChild(groupposition,childposition)).setSelected("0");            }        }    });    return convertVIEw;}
最佳答案首先,以简单列表视图为例,而不是可扩展列表视图. ListVIEw是容纳一堆Items的容器.
每个项目都有子视图,这些视图由构成ListVIEw中一行的各个元素组成.即不同的文本视图等.
适配器的getVIEw()对数据集进行 *** 作,然后在列表中创建项目.因此,如果更改用于创建适配器的数据集,并调用notifyDatasetChanged(),则会更新列表视图.

现在在你的情况下,
您可能正在使用ArrayList来表示像“norTH”这样的对象.因此,如果将count值存储在此对象中,则计数的更新将很容易.
只需使用groupposition访问列表中的数据并进行更新即可.并调用notifyDatasetChanged.

假设您使用了mList类型的ArrayList来创建适配器

// ArrayList

所以在getChildVIEw()中你写道:

@OverrIDe    public voID onClick(VIEw v) {        boolean isChecked = ((CheckBox) v).isChecked();        ApplicationController.getEventBus().post(((OutletData) getChild(groupposition,childposition)).getoutletID());        if (isChecked) {            // your code             int count = ((OutletListData) getGroup(groupposition)).getCount();            count++;            ((OutletListData) getGroup(groupposition)).setCount(count);            notifyDataSetChanged();        } else {            // your code;            int count = ((OutletListData) getGroup(groupposition)).getCount();            count--;            ((OutletListData) getGroup(groupposition)).setCount(count);            notifyDataSetChanged();        }    }

现在,这种方法的唯一限制是count应该是Object的一部分.因此,如果您是第一次从其他地方初始化计数而不是从Object本身,我建议您将计数存储在Object本身,并从那里初始化textVIEw的值.
所以在getGroupVIEw()中

groupVIEwHolder.GroupCount.setText(""+((OutletListData) getGroup(groupposition)).getCount());
总结

以上是内存溢出为你收集整理的android – 从ExpandableListView的getChildView()访问groupview的TextView全部内容,希望文章能够帮你解决android – 从ExpandableListView的getChildView()访问groupview的TextView所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1139239.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)