2010-06-12 59 views
1

我有ListView和按鈕低於活動:Android的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="fill_parent" 
    android:orientation="vertical"> 

    <ListView android:id="@+id/lvLamps" android:layout_width="fill_parent" 
     android:layout_height="fill_parent" android:listSelector="@null" 
     android:choiceMode="none" android:scrollbarStyle="insideInset" 
     android:layout_weight="1.0" /> 

    <RelativeLayout android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:orientation="horizontal" 
     android:layout_weight="0.0"> 

     <Button android:id="@+id/btnAdd" android:background="@null" 
      android:drawableLeft="@drawable/btn_upgrade" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:drawableRight="@drawable/lbl_upgrade" 
      android:textSize="0pt" android:text="" 
      android:layout_alignParentLeft="true" android:padding="20px" /> 


     <Button android:id="@+id/btnNext" android:background="@null" 
      android:drawableRight="@drawable/next_btn" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:drawableLeft="@drawable/lbl_next" 
      android:textSize="0pt" android:text="" 
      android:layout_alignParentRight="true" android:padding="20px" 
      android:visibility="gone" /> 

     <ImageButton android:id="@+id/btnListExit" 
      android:background="@null" android:src="@drawable/btn_x" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" android:padding="20px" /> 

    </RelativeLayout> 
</LinearLayout> 

的ListView行包含刪除按鈕:onClickListener設置

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" android:layout_height="wrap_content" 
    android:orientation="horizontal" android:focusable="true"> 
    <RelativeLayout android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" android:focusable="true"> 
     <ImageButton android:id="@+id/btnRowDelete" 
      android:src="@drawable/btn_x" 
      android:background="@null" android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" android:padding="4px" 
      android:focusable="true" android:focusableInTouchMode="true"/> 
      <TextView android:id="@+id/txtLampRowFrom" android:text="123" 
       android:layout_width="wrap_content" 
        android:layout_height="wrap_content" android:textSize="6pt" 
        android:layout_toRightOf="@id/btnRowDelete" 
        android:focusable="false" 
        android:textColor="@color/textColor"/> 
      <TextView android:id="@+id/txtLampRowTo" android:text="123" 
       android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
       android:textSize="6pt" 
        android:layout_toRightOf="@id/btnRowDelete" 
        android:layout_alignParentBottom="true" 
        android:focusable="false" 
        android:textColor="@color/textColor"/> 
     <ImageView android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/arrow_upgrade_to" 
      android:layout_alignParentRight="true" 
      android:layout_centerVertical="true" android:focusable="false"/> 
    </RelativeLayout> 
</LinearLayout> 

適配器,巴頓,也有一些模擬列表不可選:

// disabling list items select 
    public boolean areAllItemsEnabled() { 
     return false; 
    } 

    public boolean isEnabled(int position) { 
     return false; 
    } 

我想要的是:

  • 始終顯示在屏幕底部的按鈕列表之後(不管它有多長,應該有,如果它太長,滾動)
  • 的ListView不應該是可選擇的,我不想行選擇
  • 行刪除按鈕應該是可選擇的(可調焦)觸摸和帶軌跡球

,一切工作只是我不能集中行刪除按鈕帶軌跡球(儘管它正與觸摸)。你可以幫我嗎?

謝謝!

回答

0

使用

listView.setItemsCanFocus(true); 
+0

很抱歉,但它不是幫助...... – 2010-07-14 05:27:59

+0

我相信,你的按鈕可與上面的代碼集中,但你就是不能看到它。 嘗試使用常規按鈕而不是ImageButton,您會看到該按鈕可以被聚焦。 如果您想使用ImageButton,您需要指定按鈕在聚焦時的外觀。聚焦時,您需要爲按鈕顯示不同的圖像。要做到這一點,你需要使用一個選擇器。 檢查此鏈接以瞭解如何編寫選擇器http://androidwizard.net/2010/02/custom-button-backgrounds-using-a-selector-xml-layout/ Sry for late answer ...;) – Palo 2010-07-21 13:49:12