我们可以在单个文本视图中同时提供onTouchListener事件和onClickListener吗? [英] Can we give both onTouchListener event and onClickListener on a single text view?

查看:93
本文介绍了我们可以在单个文本视图中同时提供onTouchListener事件和onClickListener吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以在单个文本视图上同时提供onTouchListener事件和onClickListener吗...如果可以,请提供示例代码. 谢谢 阿里

Can we give both onTouchListener event and onClickListener on a single text view...if yes can I have sample code for it.. Thanks Ali

是的,谢谢你的朋友..有效!!!但是有一个小问题,我正在使用OnClick来向上移动文本和dowm,而使用OnCreateContextMenuListener来显示菜单列表...问题是如果我使用OnCreateContextMenuListener来处理textview1,那么onclick不会在Textview1上执行.知道....我需要您的建议..谢谢–

Yes thank you friends..it works!!! But there is a small issue I am using OnClick for for moving text up and dowm and OnCreateContextMenuListener for showing menu list...Problem here is if I am using OnCreateContextMenuListener for textview1 then onclick is not performing on the Textview1...Why I dont know....I need your suggestion ..thank you –

推荐答案

您在这里:

TextView tv = (TextView) getActivity().findViewById(R.id.textview_example);
                tv.setOnClickListener( new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub
                        //YOUR CODE HERE
                    }
                });

                tv.setOnTouchListener( new OnTouchListener() {

                    @Override
                    public boolean onTouch(View v, MotionEvent event) {
                        // TODO Auto-generated method stub
                        //YOUR CODE HERE
                        return false;
                    }
                } );

您必须记住,当您收到ClickEvent时,也许也会触发TouchEvent.

You have to remember that maybe a TouchEvent will be also fired when you receive a ClickEvent.

更新:

我认为,如果您查看 查看全文

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