Java Android ListView:从getChildAt()返回多个视图中的一个?
我试图从包含多个视图的ListView项中获取一个指定视图。现在,我的xml布局文件中有两个视图 playlist_item.xml:Java Android ListView:从getChildAt()返回多个视图中的一个?,java,android,xml,listview,android-listview,Java,Android,Xml,Listview,Android Listview,我试图从包含多个视图的ListView项中获取一个指定视图。现在,我的xml布局文件中有两个视图 playlist_item.xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_par
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<Button
android:id="@+id/playlist_button"
android:layout_width="240dp"
android:layout_height="80dp"
android:background="@android:drawable/btn_default"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="left|center_vertical|center_horizontal"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:textSize="21sp" />
</LinearLayout>
不幸的是,我不能再直接将其强制转换为按钮,因为现在它返回按钮和布局视图(?)我怎么能只得到按钮?谢谢 使用
Button b = (Button) listView.getChildAt(childIndex).findViewById(R.id.playlist_button);
Try View v=listView.getChildAt(childIndex);按钮b=(按钮)v.findViewById(R.id.playlist_按钮);
Button b = (Button) listView.getChildAt(childIndex);
Button b = (Button) listView.getChildAt(childIndex).findViewById(R.id.playlist_button);