隐藏儿童/取消隐藏ImageView的一组中的孩子单击Expandablelistview [英] Hide/Unhide Imageview of children in a group on child click Expandablelistview

查看:156
本文介绍了隐藏儿童/取消隐藏ImageView的一组中的孩子单击Expandablelistview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现一个方案,其中用户将选择在许多组中的一个选项。见下图:

I am trying to implement a scenario in which user will select one option among many in a group. See picture below:

问题是,当我点击一个孩子,它没有隐藏/取消隐藏点击的孩子对号形象。

Problem is that, when I click on a child, it does not hide/unhide the checkmark image of the clicked child.

我的code是如下:

childLayout.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="10dip"  >

<TextView
        android:id="@+id/childname"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="medium Text"
        android:layout_alignParentLeft="true" 

        android:textAppearance="?android:attr/textAppearanceMedium"/>

<ImageView
    android:id="@+id/checkmark"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/childname"
    android:layout_alignParentRight="true"
    android:layout_marginRight="22dp"
    android:background="@android:color/transparent"
        android:visibility="invisible"
    android:src="@drawable/checkmark" />

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/childname"
    android:layout_marginRight="53dp"
    android:layout_toLeftOf="@+id/checkmark"
    android:src="@drawable/splitthehalfbutton" />

</RelativeLayout>

在childclick监听器

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

    CreatePizzaAdapter adapter = (CreatePizzaAdapter) parent.getExpandableListAdapter();

    for (int i = 0; i < adapter.getChildernCount().get(groupPosition); i++) {

        ImageView checkbox = (ImageView) v.findViewById(R.id.checkmark);

        if(i == childPosition)//toggle hidden
        {
            if(checkbox.getVisibility() == View.INVISIBLE)
                    checkbox.setVisibility(View.VISIBLE);
            else
                checkbox.setVisibility(View.INVISIBLE);
        }
        else//keep others hidden
        {
            checkbox.setVisibility(View.INVISIBLE);
        }
    }

    return true;
}

我不知道我做错了... plz帮助我..谢谢。如果您需要任何额外的code,只是告诉我。

I don't know what I am doing wrong... Plz help me.. Thanks. If you need any additional code, just tell me.

推荐答案

试试这个:

@Override
public boolean onChildClick(ExpandableListView parent, View v,
                int groupPosition, int childPosition, long id)
{
  int iCount;
  int iIdx;
  Object item;

  CreatePizzaAdapter adapter = (CreatePizzaAdapter) parent.getExpandableListAdapter();

  iCount = adapter.getChildrenCount(groupPosition);
  for ( iIdx = 0; iIdx < iCount; ++iIdx )
  {
    item = adapter.getChild(groupPosition, iIdx);
    if ( item != null )
    {
      // Here you would cast item to the appropriate type for this row

      if ( iIdx == childPosition )
      {
        // Here you would toggle checked state in the data for this item
      }
      else
      {
        // Here you would clear checked state in the data for this item
      }
    }
  }
  parent.invalidateViews(); // Update the list view
}

这篇关于隐藏儿童/取消隐藏ImageView的一组中的孩子单击Expandablelistview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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