2013-05-14 38 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 感謝。