2013-05-14 41 views
1

这是子元素的onclick监听器。默认Onclick在expandablelistview中的子元素?

getExpandableListView().setOnChildClickListener(new ExpandableListView.OnChildClickListener() { 

     @Override 
     public boolean onChildClick(ExpandableListView parent, View v, 
       int groupPosition, int childPosition, long id) { 
      // TODO Auto-generated method stub 
      onChild_Click(parent,v, 
       groupPosition,childPosition, id); 
      return true; 
     } 
    }); 

它点击子元素时正在工作。现在我需要选择第一个孩子作为默认(在onCreate()方法内)。 对于扩展组,我正在使用这个。

getExpandableListView().expandGroup(0); 

我想这些事,子元素,但是当点击子,它正在它不发射的onclick event.But。

getExpandableListView().setItemChecked(1, true); 

getExpandableListView().setSelectedChild(0, 0, true); 

回答

0

首先你必须设置你的expandableListView选择模式单一.. 我会告诉你:

expListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); 
expListView.setItemChecked(numberOfChildToCheck+numberOfGroupThatIsOpened+1, true); 

,如果你想要的工作正确地,当打开一个组时,你必须折叠其他组。 接下来,您需要设置expListView子项的背景可以使用选择器。

这里是背景的xml文件:

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android" android:exitFadeDuration="@android:integer/config_shortAnimTime"> 


    <item android:drawable="@drawable/selected_backgroun" android:state_activated="true"/> 
    <item android:drawable="@drawable/simple_background"/> 

</selector> 

有通过您设置为一个子项的观点,即膨胀的布局。你必须设置

android:background="@drawable/name_of_your_xml_file_with_selector 

如果它不是那么清楚,你可以问问题,我会告诉你所有的图像 会这个样子.. enter image description here 感谢。