我想將按鈕添加到我的列表視圖的每一行。我在我的佈局文件夾中創建了一個名爲row.xml
的XML文件,並在該文件中添加了兩個文字瀏覽和一個按鈕。但是當添加一個按鈕時,我無法點擊列表視圖的項目。我只能點擊按鈕。這裏是row.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_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/text11"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:textColor="#000000"
/>
<TextView
android:id="@+id/text2"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10sp"
android:textColor="#000000"
/>
<Button android:text="Button" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>
我想在我的活動中引用textviews和按鈕。請幫助我並提出一些建議。
感謝朋友。我知道了。但我如何通過它們的id找到按鈕,因爲它們在row.xml中,而我的主佈局文件是不同的。請幫助 – hussain
@hussain:看看我編輯的答案。 – user370305
button =(Button)view.findViewById(R.id.btn);這裏的view是你膨脹之後的你的rw.xml文件的視圖。 – user370305