ickListener和setOnLongClickListen

ickListener和setOnLongClickListen

本文介绍了单按钮问题setOnClickListener和setOnLongClickListener电话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要你们的帮助,如果任何人都可以,这将是我的解决办法伟大的事情。我不知道是否有可能或没有,但我想尝试解决这个问题的任何如何..其实我想实现两个方法上一个按钮单击事件,它的简单的点击并长按,在这里我的code ::

I need your help if any one can be, it will be great thing for my solution.I don't know is it possible or not, but I want to try to fix this out any how..Actually I want to implement two method on single button click event, its simple click and long click, here my code ::

homebutton = (ImageButton) findViewById(R.id.home_icon);
homebutton.setOnClickListener(new OnClickListener() {
    public void onClick(View arg0) {
        Intent intent = new Intent(context, MainActivity.class);
        startActivity(intent);
    }
});
homebutton.setOnLongClickListener(new OnLongClickListener() {
    public boolean onLongClick(View arg0) {
        Toast.makeText(getApplicationContext(), "Long Clicked " , Toast.LENGTH_SHORT).show();
        return false;
    }
});

所以,在这里我得到一些错误,甚至只需点击一下完美地工作,并长按也在努力,但问题是,经过漫长的Click事件自身也开始MainActivity中的onClick方法上面code定义。

So, here i am getting something wrong, even single click is working perfectly, and long click is also working, but problem is that after long click event its also start MainActivity as defined in above code of onClick method..

这是不应该做的,返回false也在那里,仍然没有工作,因为我想..因此,有人请帮我把它解决。

That should not be done, return false is also there, still not working as i want..So, anybody please help me to get it resolve..

在此先感谢。

推荐答案

我相信你需要的返回 TRUE onLongClick 方法 - 告诉了触摸事件被消耗的框架,并没有进一步的事件处理需要

I believe you need to return TRUE in your onLongClick method - telling the framework that the touch event is consumed and no further event handling is required.

homebutton.setOnLongClickListener(new OnLongClickListener() {
    public boolean onLongClick(View arg0) {
        Toast.makeText(getApplicationContext(), "Long Clicked " ,
              Toast.LENGTH_SHORT).show();

        return true;    // <- set to true
    }
});

这篇关于单按钮问题setOnClickListener和setOnLongClickListener电话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 21:54