Android - dispatchTouchEvent给了我一个StackOverflowError

时间:2012-07-14 18:12:47

标签: android

这里我有一个带有setOnTouchListener的ViewFlipper可以正常工作。然后我给ReLayNewsItem充气,然后我把它添加到ViewFlipper。

现在我希望WebView(web)监听触摸事件并将它们传递给ViewFlipper。

    final ViewFlipper VFnewsFeed = new ViewFlipper(this);

    VFnewsFeed.setOnTouchListener(new OnTouchListener(){
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (gestureDetectorLR.onTouchEvent(event)) { return true; }
            else { return true; }
        }});

    ///////////////////

    LayoutInflater inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    RelativeLayout ReLayNewsItem = (RelativeLayout) inflater.inflate(R.layout.newsitem, null); 

    final WebView web = (WebView)ReLayNewsItem.findViewById(R.id.NewsItemWv);

    web.setOnTouchListener(new OnTouchListener(){
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            VFnewsFeed.dispatchTouchEvent(event); /// ERROR HERE!
            return false;
        }});

然而它给了我这个 -

07-14 21:12:43.600: E/AndroidRuntime(14048): FATAL EXCEPTION: main
07-14 21:12:43.600: E/AndroidRuntime(14048): java.lang.StackOverflowError
07-14 21:12:43.600: E/AndroidRuntime(14048):    at life.iface.main$11.onTouch(main.java:1289)
07-14 21:12:43.600: E/AndroidRuntime(14048):    at android.view.View.dispatchTouchEvent(View.java:4605)
07-14 21:12:43.600: E/AndroidRuntime(14048):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1518)
07-14 21:12:43.600: E/AndroidRuntime(14048):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1320)
...

有什么想法吗?谢谢! ;)

1 个答案:

答案 0 :(得分:0)

如果您返回false,则表示该活动未处理

根据您的需要,尝试使用true方法而不是VFnewsFeed.dispatchTouchEvent(event)返回onTouchfalse

Reference to documentatnion