图像可在expandablelistview中单击

时间:2012-06-06 11:41:16

标签: android expandablelistview

我在expandiblelistview组的右侧有一个imagen。 我希望当我点击图片时,这会扩展de group,但是当我点击图片时,这不会做任何事情。

我的onCreate中有这个代码,我不知道这是否必须在de expandable list adapter中。

    /*****************************************************************/
// Elementos del layout
        expLista = getExpandableListView();
        expLista.setItemsCanFocus(true);
        expLista.setOnGroupClickListener(new OnGroupClickListener() {

            @Override
            public boolean onGroupClick(ExpandableListView parent, View v,
                    int groupPosition, long id) {
                grupoCLickeado = groupPosition;
                ImageView btnExpandir = (ImageView) v
                        .findViewById(R.id.imgExpandir);
                btnExpandir.setFocusable(false);
                btnExpandir.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        expLista.expandGroup(grupoCLickeado, true);
                    }
                });
                expLista.setOnGroupExpandListener(new OnGroupExpandListener() {

                    @Override
                    public void onGroupExpand(int groupPosition) {
                        expLista.collapseGroup(groupPosition);
                        codigoServicio = numerosServicios.get(groupPosition);
                    }

                });

                return false;
            }
        });

1 个答案:

答案 0 :(得分:0)

您必须使用 setOnGroupClickListener ,而不是 onGroupExpandListener

而不是这个,

expLista.setOnGroupExpandListener(new OnGroupExpandListener() {

                @Override
                public void onGroupExpand(int groupPosition) {
                    expLista.collapseGroup(groupPosition);
                    codigoServicio = numerosServicios.get(groupPosition);
                }

            });

使用此,

expLista.setOnGroupClickListener(new OnGroupClickListener() {

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

                        expLista.collapseGroup(groupPosition);
                        return true;
                    }
                    return true;
                }
            });