Android Fragment中的问题:仍然单击上一个片段 [英] issue in Android Fragment : still click on previous fragment

查看:65
本文介绍了Android Fragment中的问题:仍然单击上一个片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个应用程序,该应用程序具有导航抽屉,并且抽屉中有很多片段,因此当我打开片段中的片段时遇到问题,在一个片段中,当用户单击listview项时,它们具有List视图,因此他们获取与列表项相关的数据我面临的问题是它仍然单击不可见的列表,但单击

I have developed an application that have navigation Drawer and many fragment inside drawer so I getting issue while I am open fragment inside fragment, in one fragment I have List view when user click on listview item they getting data related to list item so I facing problem its still click on list that is not visible but click

片段布局

 <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);
            transaction.addToBackStack(null);
            transaction.commit();

            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);

推荐答案

看看我的这个问题:

点击了片段后面的不可见布局:

在这种情况下以及被接受的答案中,对我有帮助的是添加

What helped me in this case and as the accepted answer states is to add the

android:clickable="true"

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

property to the top hierarchy ViewGroup of the layout you designed for the fragment on top ( the one that is being clicked through). That way the top fragment intercepts your clicks no matter where they occur (and even if no action is applied to it) and are not being passed to the lower level fragment/activity layout.

这篇关于Android Fragment中的问题:仍然单击上一个片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆