我正在使用帶有ListView的自定義適配器並使用自定義佈局來提供列表項目視圖。我的佈局是這樣的Android TableView作爲ListView中的itemview不可點擊
> LinearLayout
> TableView
> TableRow
> TextView
> TextView
這將導致不響應點擊列表中的項目,但如果我編輯的版面以下它的工作原理
> LinearLayout
> TextView
> TextView
所以我知道,有什麼錯我的適配器和活動。
我曾嘗試加入android:descendantFocusability="blocksDescendants"
頂端水平的線性佈局,在這個問題ListView items not clickable with HorizontalScrollView inside
我也嘗試添加android:clickable="true"
和android:focusable="true"
到TableView
建議,但這個也不行。
任何想法?
編輯
佈局XML源代碼
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="1"
>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:gravity="center_vertical">
<TextView
android:id="@+id/ITEMVIEW_TEXT2_lblText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:paddingRight="5dp"
android:paddingLeft="15dp"
/>
<TextView
android:id="@+id/ITEMVIEW_TEXT2_lblText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textColor="#ff385487"
android:gravity="right"
android:paddingRight="15dp"
/>
</TableRow>
</TableLayout>
</LinearLayout>
編輯
我曾嘗試加入android:focusable="false"
的建議here和here但這並不工作。
編輯
我真正想在這裏實現了佈置文本一個左對齊和其他權利的兩列。我想出了一個更好的佈局來實現這一點,不使用的TableView所以我的ListView項目保持點擊,它也使用較少的意見,這也將是更有效的,這是它
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/ITEMVIEW_TEXT2_lblText"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textSize="20sp"
android:paddingRight="5dp"
android:paddingLeft="15dp"
/>
<TextView
android:id="@+id/ITEMVIEW_TEXT2_lblText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textColor="#ff385487"
android:gravity="right"
android:paddingRight="15dp"
/>
</LinearLayout>
這不是一個解決方案TableView使ListView項目無法點擊的問題,但我已經在這裏注意到它,以防其他任何人想要弄清楚如何做類似的佈局。
可以用粘貼xml代碼的listview佈局嗎? – 2011-01-27 13:38:03