kaikai (1) [Avatar] Offline
#1
In chapter 4, MyMovie example. I added a button to the movie_item:

<?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:gravity="center_vertical">

<CheckedTextView android:id="@android:id/text1" >
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="0.9"
android:gravity="center_vertical"
android:paddingLeft="6dip"
android:paddingRight="6dip"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"/>
<Button >
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:text="click"
android:onClick="backToTop"/>

</LinearLayout>

When running the MyMovie app, clicking on the list item will not get focus/highlight. But when clicking on the button, it does get highlighted and event fired.

According to the text, the setItemsCanFocus(false) should solve this. But it didn't work.

To get this working, I have to go into the movie_item layout & add the following attribute to the root layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" >
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical"
android:descendantFocusability="blocksDescendants">
...
</LinearLayout>

Is that an error in the book or I am just not doing it right.
I tried to invoke setItemsCanFocus(false) before & after setting the adapter. But it did not work.

Just for completeness, if we set focusable=false for each view (button, checkedTextView), it will also work w/o the need to specify setItemsCanFocus(false) or descendantFacusability attribute

Thanks,

Message was edited by:
kaikai