可扩展列表项单击无响应

时间:2013-05-08 11:24:27

标签: android expandablelistview

显示可扩展列表,但是当点击项目时,它会进入深度,并在一段时间后显示关闭并等待。 我想知道我做错了什么。请帮我。我是android新手,谢谢..

我的代码是:

public class MainActivity extends ExpandableListActivity  implements  ExpandableListView.OnChildClickListener
{
    ArrayList<Object> childItem = new ArrayList<Object>();
    ArrayList<String> groupItem = new ArrayList<String>();

    public boolean onChildClick(ExpandableListView paramExpandableListView, View paramView, int paramInt1, int paramInt2, long paramLong)
    {
        Toast.makeText(this, "Clicked On Child", 0).show();
        return true;
    }

    public void onCreate(Bundle paramBundle)
    {
        super.onCreate(paramBundle);
        ExpandableListView localExpandableListView = getExpandableListView();
        localExpandableListView.setDividerHeight(2);
        localExpandableListView.setGroupIndicator(null);
        localExpandableListView.setClickable(true);
        setGroupData();
        setChildGroupData();
        NewAdapter localNewAdapter = new NewAdapter(this.groupItem, this.childItem);
        localNewAdapter.setInflater((LayoutInflater)getSystemService("layout_inflater"), this);
        getExpandableListView().setAdapter(localNewAdapter);
        localExpandableListView.setOnChildClickListener(this);
    }

    public void setChildGroupData()
    {
        ArrayList<String> localArrayList1 = new ArrayList<String>();

        ArrayList<String> localArrayList2 = new ArrayList<String>();

        ArrayList<String> localArrayList3= new ArrayList<String>();
        ArrayList<String> localArrayList4= new ArrayList<String>();

        int i = 0; 
        int j = 0;
        int k = 0;

        if(i <= getResources().getStringArray(R.array._stories).length)
        {
          childItem.add(localArrayList1);
          localArrayList2 = new ArrayList<String>();

          if (j < getResources().getStringArray(R.array.name_kamasutra).length)
              this.childItem.add(localArrayList2);
          localArrayList3 = new ArrayList<String>();

          if (k < getResources().getStringArray(R.array.bollywood_hollywood).length)
              this.childItem.add(localArrayList3);
          localArrayList4 = new ArrayList<String>();
          }
          for (int m = 0;m< getResources().getStringArray(R.array.rate).length; m++)
          {

            this.childItem.add(localArrayList4);
            localArrayList1.add(getResources().getStringArray(R.array._stories)[i]);
            i++;
            localArrayList2.add(getResources().getStringArray(R.array.name_kamasutra)[j]);
            j++;
            localArrayList3.add(getResources().getStringArray(R.array.bollywood_hollywood)[k]);
            k++;

          localArrayList4.add(getResources().getStringArray(R.array.rate)[m]);
        }
    }

    public void setGroupData()
    {
        this.groupItem.add(getResources().getStringArray(R.array.mainlist)[0]);
        this.groupItem.add(getResources().getStringArray(R.array.mainlist)[1]);
        this.groupItem.add(getResources().getStringArray(R.array.mainlist)[2]);
        this.groupItem.add(getResources().getStringArray(R.array.mainlist)[3]);
    }
}

日志

05-08 11:20:53.504: D/dalvikvm(1003): GC_FOR_MALLOC freed 16371 objects / 524296 bytes in 59ms
05-08 11:20:53.684: D/dalvikvm(1003): GC_FOR_MALLOC freed 16371 objects / 524296 bytes in 53ms
05-08 11:20:53.904: D/dalvikvm(1003): GC_FOR_MALLOC freed 16371 objects / 524296 bytes in 53ms
05-08 11:20:54.074: D/dalvikvm(1003): GC_FOR_MALLOC freed 16371 objects / 524296 bytes in 51ms
05-08 11:20:54.245: D/dalvikvm(1003): GC_FOR_MALLOC freed 16371 objects / 524296 bytes in 53ms
05-08 11:20:54.424: D/dalvikvm(1003): GC_FOR_MALLOC freed 16371 objects / 524296 bytes in 55ms
05-08 11:20:54.605: D/dalvikvm(1003): GC_FOR_MALLOC freed 16371 objects / 524296 bytes in 56ms
05-08 11:20:54.784: D/dalvikvm(1003): GC_FOR_MALLOC freed 16371 objects / 524296 bytes in 56ms
05-08 11:20:54.974: D/dalvikvm(1003): GC_FOR_MALLOC freed 16371 objects / 524296 bytes in 56ms
05-08 11:20:55.154: D/dalvikvm(1003): GC_FOR_MALLOC freed 16371 objects / 524296 bytes in 54ms
05-08 11:20:55.334: D/dalvikvm(1003): GC_FOR_MALLOC freed 16371 objects / 524296 bytes in 58ms
05-08 11:20:55.524: D/dalvikvm(1003): GC_FOR_MALLOC freed 16371 objects / 524296 bytes in 62ms
05-08 11:20:55.704: D/dalvikvm(1003): GC_FOR_MALLOC freed 16371 objects / 524296 bytes in 56ms
05-08 11:20:55.884: D/dalvikvm(1003): GC_FOR_MALLOC freed 16371 objects / 524296 bytes in 53ms
05-08 11:20:56.064: D/dalvikvm(1003): GC_FOR_MALLOC freed 16371 objects / 524296 bytes in 57ms
05-08 11:20:56.245: D/dalvikvm(1003): GC_FOR_MALLOC freed 16371 objects / 524296 bytes in 54ms
05-08 11:20:56.434: D/dalvikvm(1003): GC_FOR_MALLOC freed 16371 objects / 524296 bytes in 58ms
05-08 11:20:56.614: D/dalvikvm(1003): GC_FOR_MALLOC freed 16371 objects / 524296 bytes in 57ms
05-08 11:20:56.794: D/dalvikvm(1003): GC_FOR_MALLOC freed 16371 objects / 524296 bytes in 51ms
05-08 11:20:56.984: D/dalvikvm(1003): GC_FOR_MALLOC freed 16371 objects / 524296 bytes in 58ms

谢谢

1 个答案:

答案 0 :(得分:0)

重写此方法“isChildSelectable”并在ExpandableListAdapter类中返回true以启用子选择。

@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
    return true;
}