I am perplexed as to why my onListItemClick()
method is not being called.
I was reading this question on the subject, and it mentions that any other components in the layout need to be set android:focusable="false"
However, here is my layout for that class. As you can see, it has no other components:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
</LinearLayout>
I checked in the layout for the parent activity, and it does have some other components, namely a drawer layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<FrameLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/fragment_container">
</FrameLayout>
<!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. -->
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- As the main content view, the view below consumes the entire
space available using match_parent in both dimensions. -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- android:layout_gravity="start" tells DrawerLayout to treat
this as a sliding drawer on the left side for left-to-right
languages and on the right side for right-to-left languages.
The drawer is given a fixed width in dp and extends the full height of
the container. A solid background is used for contrast
with the content view. -->
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
</android.support.v4.widget.DrawerLayout>
You can see that my ListFragment is being contained in the FrameLayout
called fragment_container
.
Could the DrawerLayout
be preventing calls to my onListItemClick()
method?
And, if so, how can I set is as unfocusable (it's a pretty huge layout...where should I put the android:focusable="false"
)?
I discovered the issue. I added a FrameLayout
to contain my Fragment
, but I see now that the DrawerLayout
already contains within it a FrameLayout
(called content_frame
). So I just used content_frame
instead of fragment_container
.