2011-01-27 38 views
2

我正在使用帶有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"的建議herehere但這並不工作。


編輯

我真正想在這裏實現了佈置文本一個左對齊和其他權利的兩列。我想出了一個更好的佈局來實現這一點,不使用的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項目無法點擊的問題,但我已經在這裏注意到它,以防其他任何人想要弄清楚如何做類似的佈局。

+0

可以用粘貼xml代碼的listview佈局嗎? – 2011-01-27 13:38:03

回答

0

我正在使用TableLayout和TableRow的組合來絆倒類似的問題。

我的解決方案如下: TableRow似乎沒有自己的Selector,因此即使將其定義爲可點擊和可聚焦,您也將永遠看不到視覺差異。 我爲TableRow分配了一個背景,這與GridView使用的背景相當(可以在android-sdk-windows \ platforms \ android-10 \ data \ res \ drawable \ grid_selector_background.xml下的SDK中找到) 。

之後,它完全可以聚焦和點擊。