2013-09-25 34 views
0

我有自定义ExpandableListViewExpandableListView布局:ExpandableListView中的按钮

<RelativeLayout 
    android:id="@+id/layout_nutrition_list" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@android:color/background_dark" > 

    <ExpandableListView 
     android:id="@+id/elv_nutrition" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="10dp" 
     android:indicatorLeft="10dp" 
     android:divider="@color/gold_color" 
     android:listSelector="@android:color/transparent" /> 

</RelativeLayout> 

组布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_marginLeft="5dp" 
android:layout_gravity="center_vertical" 
android:paddingLeft="10dp" 
android:paddingTop="5dp" 
android:paddingBottom="5dp" 
android:background="@drawable/lv_item_bg" 
android:contentDescription="@null" 
android:descendantFocusability="blocksDescendants"> 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="5dp" 
    android:layout_centerVertical="true" 
    android:textColor="@color/gold_color" 
    android:textSize="18sp" 
    android:typeface="serif" 
    android:contentDescription="@null" /> 

<ImageButton 
    android:id="@+id/btn_func" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_centerVertical="true" 
    android:background="@drawable/lv_item_bg" 
    android:contentDescription="@null" 
    android:onClick="BtnCategMore" 

    android:scaleType="center" /> 


</RelativeLayout> 

我怎样才能点击按钮后btn_func访问父视图?我需要从textView1获得文字。

感谢您的提前!

回答

1

如何将此groupLayout xml附加到您的适配器中。实际上,您必须在ExpandableListAdapter中实施方法getGroupView()。在那里你可以膨胀这个布局并从这个布局访问所有的视图。

+0

谢谢。通过在getGroupView方法中添加setOnClickListener来解决。 – Andrew

相关问题