在我的ExpandableListView适配器中重复 [英] Duplicates in my ExpandableListView Adapter

查看:290
本文介绍了在我的ExpandableListView适配器中重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是,每当我在ExpandableListView中向一个GroupItem中添加多个Child时,该项目都与前一个子项重复。我已经缩小到我的ExpandableListView(自定义)适配器中的getChild()方法。

getChild()方法如下所示:

  public Object getChild(int groupPosition,int childPosition){

return rCollection.get(weekData.get(groupPosition))。get (childPosition);

$ b

其中 rCollection = Map< String ,< Custom>> ;;
weekData = List< String> ;

我如何更改getChild每个请求只返回一个项目,所以我不重复?我不能使用for循环,因为如果我将groupPosition和childPosition更改为数组,我将不得不再次实现该方法。为了说明,这是问题例如:



第一次被调用时,我如何排除项目2的被拾取,以及如何在第二次调用项目1时不被调用?等等。



感谢您的阅读和所有帮助。 解决方案

  @Override 
public int getChildCount(.....)
{
return 2;



$ b $ p
$ b

如果您确定每个项目只有2个子项目


对不起,这是你想要的正确方法。

编辑


  @Override 
public int getChildrenCount(int groupPosition)
{
return(rCollection.get(weekdata.get(groupPosition()))。size();
}

这将返回您的列表< Custom> 的大小(长度)

如果需要的话,
均衡paranthesis

the problem goes is that everytime I add more than one Child to a GroupItem in my ExpandableListView, the item duplicates itself with the previous child. I have narrowed it down to the getChild() method in my ExpandableListView (custom) adapter.

The getChild() method looks like this:

public Object getChild(int groupPosition, int childPosition) {

     return rCollection.get(weekData.get(groupPosition)).get(childPosition);

}

Where rCollection = Map<String, List<Custom>>; and weekData = List<String>;

How do I change the getChild to return only one item per request so I dont get duplicates? I cannot use a for-loop because if I change the groupPosition and childPosition to Arrays I will have to implement the method again.

To Illustrate, this is what the issue looks like:

How do I exclude the Item 2 from being picked up by the first time it is called, and how do I exclude item 1 from being called the second time it is called? And so on.

Thank you for reading and all the help.

解决方案

@Override
public int getChildCount(.....)
{
     return 2;
}

If you are sure that for every item there are only 2 subitems
Sorry my bad this is the right method you want.
EDIT

@Override
public int getChildrenCount(int groupPosition)
{
    return (rCollection.get(weekdata.get(groupPosition())).size();
}

This will return the size (length) of your List<Custom> for a map.
balance paranthesis if needed

这篇关于在我的ExpandableListView适配器中重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆