Android片段中的问题:仍然单击上一个片段

Android片段中的问题:仍然单击上一个片段,android,android-fragments,android-fragmentactivity,Android,Android Fragments,Android Fragmentactivity,我已经开发了一个应用程序,其中有导航抽屉和抽屉中的许多片段,所以我在打开片段中的片段时遇到了问题,在一个片段中,当用户单击listview项时,我有列表视图,他们获取了与列表项相关的数据,所以我面临的问题仍然是单击不可见但单击的列表 碎片布局 <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/layo

我已经开发了一个应用程序,其中有导航抽屉和抽屉中的许多片段,所以我在打开片段中的片段时遇到了问题,在一个片段中,当用户单击listview项时,我有列表视图,他们获取了与列表项相关的数据,所以我面临的问题仍然是单击不可见但单击的列表

碎片布局

 <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layoutDrawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:clickable="true"
        android:background="@drawable/backgroung"
        android:id="@+id/content_frame"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"></FrameLayout>

    <LinearLayout
        android:id="@+id/linearDrawer"
        android:layout_width="@dimen/dp260"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="@color/white"
        android:layout_gravity="start">

        <RelativeLayout
            android:id="@+id/userDrawer"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@color/white"
            android:layout_margin="@dimen/dp10">

从中间到结尾编辑代码提交行

    Fragment fragment = new FragmentContactDetails();
                FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
                transaction.add(((ViewGroup) getView().getParent()).getId(), fragment);


                Bundle args = new Bundle();
                int index = adapter.arrayList.indexOf(adapter.propertyList.get(position));

                args.putInt(Constant.POSITION, index);
                Toast.makeText(getActivity(), "" + index + "----" + adapter.propertyList.get(position).getName(), Toast.LENGTH_LONG).show();
                fragment.setArguments(args);
transaction.addToBackStack(null);
                transaction.commit();

看看我的这个问题:

在这种情况下,正如公认的答案所述,帮助我的是添加

android:clickable=“true”


属性设置为为顶部片段(正在单击的片段)设计的布局的顶部层次结构
ViewGroup
。这样,顶部片段会拦截您的点击,无论点击发生在何处(即使没有对其应用任何操作),并且不会传递给较低级别的片段/活动布局

添加事务。提交();在fragment.setArguments之后的最后一行,我必须在主框架布局中实现这个标记,否则..?这是一个救命稻草。非常感谢。简单有效的解决方案。谢谢男人:)救生员:)谢谢你。工作得很有魅力,非常感谢。我尝试了一种非常困难的方法,但在尝试这种方法之前,我曾想过谷歌搜索一次,结果真的得到了回报。
    Fragment fragment = new FragmentContactDetails();
                FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
                transaction.add(((ViewGroup) getView().getParent()).getId(), fragment);


                Bundle args = new Bundle();
                int index = adapter.arrayList.indexOf(adapter.propertyList.get(position));

                args.putInt(Constant.POSITION, index);
                Toast.makeText(getActivity(), "" + index + "----" + adapter.propertyList.get(position).getName(), Toast.LENGTH_LONG).show();
                fragment.setArguments(args);
transaction.addToBackStack(null);
                transaction.commit();