为什么我的片段的ontouch()和的onClick()方法仍然响应时,它已经开始另一frament [英] Why my fragment's ontouch() and onClick() method still response when it has started another frament

查看:211
本文介绍了为什么我的片段的ontouch()和的onClick()方法仍然响应时,它已经开始另一frament的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序有一个片段A和B片段,该片段A包含一个 GridView控件的ListView 象下面这样

My app has a fragment A and fragment B, the fragment A contains a GridView and a ListView like below:

             fragment A
-------------------------------------
|                       |            |
|                       |            |
|                       |            |
|        GridView A     | ListView A |
|                       |            |
|                       |            |
|                       |            |
|                       |            |
|                       |            |
--------------------------------------

和片段B包含一个的ListView 的LinearLayout 如下:

and the fragment B contains a ListView and a LinearLayout as below:

--------------------------------------
|            |                       |
|            |                       |
|            |                       |
|            |                       |
| ListView B |     LinearLayout B    |
|            |                       |
|            |                       |
|            |                       |
|            |                       |
|            |                       |
--------------------------------------

在单击的ListView 的片段A A的项目时,将启动B片段,并显示该项目的详细信息。但在B片段,当我触摸这曾经是的GridView领域的屏幕 A或的ListView A,它还是响应 GridView控件 A的onTouch()方法或的ListView A的的onClick()方法。这是我第一次用片段,我已经混淆这一段时间孤独

When a click a item of ListView A on fragment A, it will start fragment B and shows the details information of the item. But at the fragment B when I touch the screen which used to be the area of GridView A or ListView A, it still response the GridView A's onTouch() method or ListView A's onClick() method. This is the first time I used Fragment, I have confusing this for a lone time.

推荐答案

这听起来像触摸被通过对第一个片段泄漏。我将在B片段的根布局,以prevent从经历时,它的布局是可见触摸设置onTouch监听器。

It sounds like the touches are leaking through to the first fragment. I would set a onTouch Listener on the root layout of fragment B to prevent the touches from going through when its layout is visible.

因此​​,对于这些方针的东西:

So for something along these lines:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
     View root = inflater.inflate(R.layout.fragmentBlayout, container, false);
    root.setOnTouchListener(new OnTouchListener()
    {
        @Override
        public boolean onTouch(View v, MotionEvent event)
        {
        /** Intercepts touches from going through. */
        return true;
        }
    });

    /** Find the rest of your views... */

   return root;
}

这篇关于为什么我的片段的ontouch()和的onClick()方法仍然响应时,它已经开始另一frament的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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