如何让视图组中expandablelistview在android系统? [英] how to get view of group in expandablelistview in android?

查看:253
本文介绍了如何让视图组中expandablelistview在android系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IM blazilian所以,我的英语不是很好。

im blazilian so, my english is not good.

所以..我需要得到视图组中expandablelistview为得到你的对象标记throught view.getTag()方法。

So.. i need get view of group in expandablelistview for get your object tag throught view.getTag() method.

跟着我在这个例子:

 ExpandableListView

    --> group (i need this view)
    ----> child
    ----> child
    ----> child

    --> group (i need this view)
    ----> child
    ----> child

我的code:

    @Override
public boolean onChildClick(final ExpandableListView parent, final View v,
        final int groupPosition, final int childPosition, final long id) {

        /* I NEED GET VIEW OF GROUP FOR GET YOUR TAG*/

        View vParent = parent.getChildAt(groupPosition); // dont work after first group 
        Programa v2 = (Programa) parent.getTag(); // return null

        // v parameter is a child of group

    return true;
}

在我的适配器:

    @Override
public View getGroupView(int groupPosition, boolean isExpanded,
        View convertView, ViewGroup parent) {

    TwoLineListItem view = (TwoLineListItem) LayoutInflater.from(contexto)
            .inflate(android.R.layout.simple_expandable_list_item_2,
                    parent, false);

    String programa = map.keySet().toArray(new String[map.keySet().size()])[groupPosition];

    view.getText1().setText(programa);
    view.getText2().setText("PROGRAMA LOCAL");

    view.setTag(programas.get(groupPosition)); // i need get this in child click listener

    return convertView = view;
}

什么想法?谢谢

推荐答案

如果您code是正确的,你想获得该组查看了孩子,这样就可以调用getTag()就可以了,对不对?

If your code is correct, you want to get the group view for the child so that you can call getTag() on it, correct?

如果是这样,为什么不直接跳过这一步并访问标记的值,通过 programas.get设置(groupPosition)手动?

If so, why not just skip that step and access the value of the tag, set by programas.get(groupPosition) manually?

您可以通过调用做到这一点:

You can do this by calling:

programas.get(groupPosition)就在您的 onChildClick 方法的顶部,因为你拿到小组第一的位置值有太多。

programas.get(groupPosition) right on the top of your onChildClick method since you get the group position value there too.

编辑回应您的评论:

这里的问题是,你不会是能够通过适配器来获得该组的观点,因为它可能涉及到重新创建视图由于意见列表循环利用。如果此方法不起作用,我强烈建议你修改code,使其工作。

The issue here is that you're not going to be able to get the view of the group through the adapter since it might involve recreating the view due to recycling of views in lists. If this method doesn't work, I strongly suggest modifying your code to make it work.

如果计划成是输入您的适配器之一,然后调用 getGroup(groupPosition)您的适配器上访问它。否则,作出公开的方法在你的适配器类,以允许值的检索。

If programas is one of the inputs to your adapter, then call getGroup(groupPosition) on your adapter to access it. Else, make a public method in your adapter class to allow retrieval of that value.

这篇关于如何让视图组中expandablelistview在android系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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