Android ListView删除行按钮 - 焦点问题

时间:2010-06-12 17:56:00

标签: android user-interface listview button focus

我在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>

在适配器中,设置了按钮onClickListener,还有一些假人使列表不可选:

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

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

我想要的是:

  • 总是在列表后面的屏幕底部显示按钮(无论多长时间,如果它太长都应该滚动)
  • ListView不应该是可选的,我不想要行选择
  • 行删除按钮应该是可选择的(可聚焦的)触摸和轨迹球

一切正常,除了我无法将行删除按钮与轨迹球对焦(虽然它正在处理触摸)。你能帮助我吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

使用

listView.setItemsCanFocus(true);