如何结合OnClickListener和OnTouchListener一个的ImageButton [英] How to combine OnClickListener and OnTouchListener for an ImageButton

查看:109
本文介绍了如何结合OnClickListener和OnTouchListener一个的ImageButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要做一些事情,当用户点击的ImageButton 我试图创建一个静态类实现的两个 OnClickListener OnTouchListener

静态类ClickListenerForScrolling实现OnClickListener,OnTouchListener有以下方法:

  @覆盖
公共无效的onClick(视图v)
 

  @覆盖
公共布尔onTouch(查看为arg0,MotionEvent ARG1)
 

这背后的整个想法是改变的图像源的的ImageButton 当用户触摸它,当用户点击这个按钮执行任务。任何人都可以给我如何做这样的提示?

解决方案

  imageButton.setOnTouchListener(新View.OnClickListener(){

    公共无效onTouch(查看为arg0,MotionEvent ARG1){
        //改变背景在这里
    }
});

imageButton.setOnClickListener(新View.OnClickListener(){

    公共无效的onClick(查看为arg0){
        这里//行动
    }
});
 

I need to do something when the user clicks the imageButton I've tried to create a static class that implements both OnClickListener and OnTouchListener

static class ClickListenerForScrolling implements OnClickListener, OnTouchListener that has the following methods:

@Override
public void onClick(View v)

and

@Override
public boolean onTouch(View arg0, MotionEvent arg1)

The whole idea behind this is to change the image source of the ImageButton when the user touches it, and perform a task when the user clicks this button. Can anybody give me a hint on how to do so?

解决方案

imageButton.setOnTouchListener(new View.OnClickListener() {

    public void onTouch(View arg0, MotionEvent arg1) {
        //change background here
    }
});

imageButton.setOnClickListener(new View.OnClickListener() {

    public void onClick(View arg0) {
        //action here
    }
});

这篇关于如何结合OnClickListener和OnTouchListener一个的ImageButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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