【发布时间】:2011-03-03 01:22:38
【问题描述】:
我有一个带有 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 行包含删除按钮:
<?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>
在Adapter中,设置了按钮onClickListener,也有假人使列表不可选:
// disabling list items select
public boolean areAllItemsEnabled() {
return false;
}
public boolean isEnabled(int position) {
return false;
}
我想要的是:
- 列表后总是在屏幕底部显示按钮(不管多长,如果太长应该有滚动条)
- ListView 不应该是可选择的,我不想要行选择
- 行删除按钮应该可以通过触摸和轨迹球选择(聚焦)
一切正常,除了我无法聚焦行删除按钮使用轨迹球(虽然它可以使用触摸)。你能帮助我吗?
谢谢!
【问题讨论】:
标签: android user-interface listview button focus