I’m having a problem with an android activity that extends ListActivity. It seems like the items in the list cannot be “clicked” until after I’ve scrolled the list. After you scroll the list a little, the “clicking” works fine. If the list simply is not scrollable (not enough items, etc) then everything works as it.
Since the activity extends ListActivity I just override onListItemClick:
@Override
protected void onListItemClick(ListView l, View v, int position, long id)
{
Log.e(TAG, "Click fired");
}
The rows in the list are defined by a custom XML, and after reading through virtually all of the posts on here I’m thinking it has to do with focusable elements, but I can’t seem to get it to work. As you can see from the list XML below, all the items have focusable="false", but that didn’t help.
I’ve also tried all the options for android:descentFocusability — but none work properly.
This problem is apparent on all versions of Android from Froyo –> ICS
Edit
I have determined that this problem goes away if I remove the onScroll listener that is attached to the same list. However, I really need that and I’ve put logging info inside both onScroll and onScrollStateChanged and nothing informative shows up (e.g., scrolling isn’t being fired either.) Is this a known conflict?
Layout XML for activity in question:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:focusable="false"
android:focusableInTouchMode="false">
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Search Results: "
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_gravity="left"
android:focusable="false"
android:focusableInTouchMode="false" />
<TextView android:id="@+id/query_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="context sensitive"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_gravity="right"
android:textStyle="italic"
android:focusable="false"
android:focusableInTouchMode="false" />
</FrameLayout>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="1dip"
android:background='@color/grey'
android:focusable="false"
android:focusableInTouchMode="false" />
<ListView
android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
android:descendantFocusability="blocksDescendants" />
<TextView
android:id="@+id/prodcutdb_results_empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="5dip"
android:paddingTop='4dip'
android:text="No results"
android:focusable="false"
android:focusableInTouchMode="false"
android:visibility="gone"/>
</LinearLayout>
Custom list item XML: (adding focusable tags to the LinearLayout in this XML has no effect)
<?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="?android:attr/listPreferredItemHeight"
android:orientation="horizontal"
android:paddingRight="4dip"
android:cacheColorHint="#00000000">
<TextView
android:id="@+id/list_item_label"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:paddingLeft="20dip"
android:textSize="16dp"
android:layout_weight="1"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false" />
<view
android:layout_width="wrap_content"
android:id="@+id/list_item_image"
android:layout_height="fill_parent"
android:src="@drawable/right"
android:maxHeight="50dp"
android:maxWidth="50dp"
android:layout_gravity="right"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false" />
</LinearLayout>
To keep things short — nothing worked. I added an onClick listener to each one of the custom views.