문제

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

도움이 되었습니까?

해결책

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.

다른 팁

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

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)

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top