问题描述
我的活动中有两个片段. Fragment2重叠片段1. Fragment1占用整个屏幕.当用户点击Fragment1时,我希望Fragment2消失.
我的问题是如何确定fragment1被轻拍?
fragment1主要由一个网络视图组成,我认为我可以使用它的setOntouchListener,但似乎从未被称为.
任何建议都将不胜感激.
bradley4
这就是我实现OnTouchListener的方式:
1)首先我实施了" OnTouchListener"
public class Frag_ItemDetail extends Fragment implements OnTouchListener {
2)然后我覆盖了OnTouch
@Override public boolean onTouch(View v, MotionEvent event) { Log.d("myclass", "onTouch"); return false; }
3)然后,我将setOntouchListener设置为我的WebView
WebView itemFullDescription = (WebView) v.findViewById(R.id.itemFullDescription); WebView.setOnTouchListener(this);
我将OnTouchListenerner设置在一个按钮上,它工作正常.它只是对WebView不起作用.
推荐答案
我扩展了LinearLayout类和Overrode onInterceptTouchEvent,因此,如果触摸Fragment1 Fragment2将消失,这正在工作.
其他推荐答案
您的返回false不应该返回true吗?如果触摸了活动2(或WebView),则应以true返回.或VICE反之亦然
问题描述
I have two fragments in my activity. Fragment2 overlaps Fragment1. And Fragment1 takes up the entire screen. When the user taps Fragment1 I would like Fragment2 to disappear.
My question is how can I determine that Fragment1 was tapped?
Fragment1 is mostly made up of a webview which I was thinking I could use its setOnTouchListener but it doesn't seem to ever be called.
Any suggestions would be appreciated.
Bradley4
This is how I implemented the onTouchListener:
1) first I implemented "OnTouchListener"
public class Frag_ItemDetail extends Fragment implements OnTouchListener {
2)then I overrode onTouch
@Override public boolean onTouch(View v, MotionEvent event) { Log.d("myclass", "onTouch"); return false; }
3) then I set the setOnTouchListener to my webview
WebView itemFullDescription = (WebView) v.findViewById(R.id.itemFullDescription); WebView.setOnTouchListener(this);
I set the onTouchListenerner on a button and it worked fine. It just isnt' working for the webview.
推荐答案
I extended the LinearLayout class and overrode onInterceptTouchEvent so if Fragment1 is touched Fragment2 would disappear, which is working.
其他推荐答案
Shouldnt your return false be return true? If activity 2 is touched(or the webview) it should be returning as true. or vice versa