views:

962

answers:

1

Hi!

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!

A: 

Use

listView.setItemsCanFocus(true);
Palo
Sorry, but it not helps...
Max Gontar
I believe that your button can be focused with the code above but you just can't see it.try to use a regular button instead of the ImageButton and you will see that the button can be focused.If you want to use an ImageButton you need to specify how should the button look like when it is focused. You will want to display a different image for the button when it is focused. To do this you need to use a Selector.Check this link to see how to write a selector http://androidwizard.net/2010/02/custom-button-backgrounds-using-a-selector-xml-layout/Sry for late answer... ;)
Palo