Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android, SlidingPaneLayout and listView

I'm using a ListView as a secondary view in my SlidingPaneLayout.The main view is a map fragment. The ListView acts as a menu. The problem is that onItemClickedListener never gets called on the ListView. Even the list row never gets highlighted on press. it seems that the ListView can't get the focus.

EDIT: actually, slidingPaneLayout.findFocus() shows that android.widget.ListView. still no luck on clicking the list items.

Here is my xml

<com.ziz.luke.custom_components.MySlidingPaneLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/slidingpanelayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ListView
        android:id="@+id/contactsList"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#00000000" >
    </ListView>

    <TextView
        android:id="@+id/android:empty"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:gravity="center_horizontal|center_vertical"
        android:text="@string/noContacts" />
</RelativeLayout>

<fragment
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.SupportMapFragment" />
</com.ziz.luke.custom_components.MySlidingPaneLayout>

How can I solve this??

like image 423
a fair player Avatar asked Jun 16 '13 20:06

a fair player


3 Answers

I've found the answer. I was using a subclass of SlidingPaneLayout in which I was overriding

onInterceptTouchEvent(MotionEvent arg0)

I was trying to do the following:

  • open the slidingPaneLayout useing a button.
  • close the slidingPaneLayout useing a button.
  • close the slidingPaneLayout useing swiping.
  • prevent the user from opening the slidingPaneLayout using swiping.

So, I created a boolean inside my subclass called shouldSwipe to be returned from the over-ridden method.

the implementation that caused the problem was :

@Override
    public boolean onInterceptTouchEvent(MotionEvent arg0) {

        return shouldSwipe;
    }

it caused the problem whenever (shouldSwipe = true) because it tells the system that the touch event already is consumed and prevents it from being propagated.

I solved that using this one:

@Override
    public boolean onInterceptTouchEvent(MotionEvent arg0) {
        // TODO Auto-generated method stub
        return shouldSwipe ?super.onInterceptTouchEvent(arg0):shouldSwipe;
    }

that's it.

like image 137
a fair player Avatar answered Sep 27 '22 20:09

a fair player


Just a suggestion but maybe using the NavigationDrawer for a Navigation List Drawer would be easier then reinventing the wheel.

http://developer.android.com/design/patterns/navigation-drawer.html

like image 32
Raanan Avatar answered Sep 27 '22 19:09

Raanan


I have just created an example project using SlidingPaneLayout.

I didn't use any map because there is not where the problem is, so I just refer the position of the map with a TextView. I did use a ListFragment that is working and receiving the click listeners. Please download the project from here:

https://dl.dropboxusercontent.com/u/33565803/StackOverFlowExamples/SlidingPaneLayoutExample.zip

Let me know if you have any configuration problem and if it solves your problem ;)

(I am using actionBarSherlock just because I am used to, so you can remove it if you want)

like image 26
jpardogo Avatar answered Sep 27 '22 18:09

jpardogo