-1

I am using a listview layout in a descendant of Activity, the Adapter's getView implementation is as follow, it's longclickable:

public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
        TextView tv = new TextView(CustomTitleActivity.this);
        tv.setText(title[position]);
        return tv;
    }
    return convertView;
}

but when I tried inflate the item's view from a layout file like this:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/local_songs_list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:focusable="false"
    android:orientation="horizontal">
    <LinearLayout
        android:layout_weight="1"
        android:focusable="false"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <TextView
            android:id="@+id/title"
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"
            android:focusable="false"
            android:text="TITLE"
            android:textAppearance="?android:textAppearanceSearchResultTitle"
            />
        <TextView
            android:id="@+id/artist"
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"
            android:text="Unknow"
            android:focusable="false"
            android:textAppearance="?android:textAppearanceSearchResultSubtitle"
            />      
    </LinearLayout>

    <LinearLayout
        android:layout_weight="3"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
            android:focusable="false"
        android:orientation="horizontal">
        <ImageButton 
        android:id="@+id/favorite"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_favourite"
            android:background="#0000"
            android:focusable="false"
            android:onClick="onToggleStar"/>

        <CheckBox 
        android:id="@+id/select"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:visibility="visible"
            android:focusable="false"/>
    </LinearLayout>
</LinearLayout>

I could not click/long click them, I already tried to set android:focusable attribute to false. Could someone give me a hint?

mwjohnson
  • 661
  • 14
  • 26
liuyong
  • 987
  • 10
  • 19

1 Answers1

1

Answer it myself. Because in constructor of ImageButton, it would call setFocusable(true) again, so if you really don't need it to be focused, it's ok to call setFocusable(false) after the ImageButton was constructed. Then the problem solved.

liuyong
  • 987
  • 10
  • 19