clicking on the fragment invokes activity behind it

后端 未结 5 1084
情书的邮戳
情书的邮戳 2021-01-01 16:31

Im guessing its something really simple, maybe a setting in listview or fragment. But I couldnt find solution for it for couple of hours now. So.. I have a listView like thi

相关标签:
5条回答
  • 2021-01-01 17:03

    Set android:clickable="true" in FrameLayout tag of your foreground Fragment

    it works for me.

    0 讨论(0)
  • 2021-01-01 17:14

    So, I had exactly the same issue, I still don't know the reason why, but make sure your adding the android:clickable="true" to the roovView of your 2nd fragment's layout.

    something like this:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    android:clickable="true"
    android:orientation="vertical">
    .....any content for your item (2nd fragment).....
    </LinearLayout>
    
    0 讨论(0)
  • 2021-01-01 17:16

    I solved a similar problem by adding android:clickable="true" in the element that was behaving as if it was "transparent". Making it clickable made sure the click events were handled by it instead of passed to the views bellow.

    0 讨论(0)
  • 2021-01-01 17:17

    Set the clickable property to true so that the click event gets consumed only on the foreground fragment.

        <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:clickable="true" />
    
    0 讨论(0)
  • 2021-01-01 17:18

    I believe the issue is that the replace method doesn't replace the ListView. It only replaces other fragments that are within the container. In this specific case there are none. Thus, you're essentially adding your fragment on top of the ListView because the RelativeLayout allows views to be on top of one another. When you click on the fragment, you're not fully handling it, so it goes through to the base view which is the ListView.

    A simple, quick, and dirty solution would be to retrieve the ListView object and either remove it from the container yourself or set it's visibility to GONE. A better solution would be to use ListFragment which should show the expected results.

    0 讨论(0)
提交回复
热议问题