Android, SlidingPaneLayout and listView
Asked Answered
W

4

5

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??

Works answered 16/6, 2013 at 20:51 Comment(3)
paste the code where you set your listeners, if your list is getting focus -and- the view looks right, then the issue probably isn't in your layout xml. Also, how do you show/hide empty?Maintain
That's what I did. same issue. and I guess it's something related to the SlidingPaneLayout itself.Works
can you post the java code as well?Maintain
W
6

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.

Works answered 19/6, 2013 at 0:8 Comment(1)
hello, i am using slidingUpPanelLayout for my app. I have swipable view with in the panel. but i am not able to swipe it to vertically. Can you Please help me for this.Anjaanjali
P
3

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)

Podolsk answered 18/6, 2013 at 23:43 Comment(0)
P
3

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

Pacer answered 24/6, 2013 at 16:10 Comment(0)
A
0

Try using this powerful library to make a simple sliding bar : https://github.com/jfeinstein10/SlidingMenu

and here is how you can import it and use it : Solved: how to import SlidingMenu on my project with ActionBarSherlock 4.2.0

Adenaadenauer answered 24/6, 2013 at 18:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.