Android ListView delete row button - focus issue
- by Max Gontar
I have an activity with ListView and buttons below:
<?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 row contains delete button:
<?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>
In Adapter, Button onClickListener is set, also there are dummies to make list non-selectable:
// disabling list items select
public boolean areAllItemsEnabled() {
return false;
}
public boolean isEnabled(int position) {
return false;
}
What I want is:
always show buttons in the bottom of screen after list (no matter how long it is, there should be scroll if it's too long)
ListView should not be selectable, I don't want row selection
row delete button should be selectable (focusable) with touch and with trackball
And everything works except I can't focus row delete button with trackball (although it's working with touch). Can you help me?
Thanks!