2010-06-12 52 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