setOnTouchlistener一个图像视图 [英] setOnTouchlistener for an image view

查看:165
本文介绍了setOnTouchlistener一个图像视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是从画廊通过startActivityForResult加载图像()
和装载在onActivity图像()。我不能实施
touchlistener该图像?参考见下文。

 保护无效的onActivityResult(INT申请code,INT结果code,
            意图数据){
        如果(要求code == SELECT_PICTURE){
        ......
        ......
          位图位图preVIEW = BitmapFactory.de codeFILE(fileSrc); //负荷preVIEW图像         setimage.setImageBitmap(位图preVIEW);
     setimage.setOnTouchListener(新OnTouchListener(){    @覆盖
    公共布尔onTouch(视图V,MotionEvent事件){
        Toast.makeText(getApplicationContext(),图像touced!,Toast.LENGTH_SHORT).show();
                        返回true;
    }
    });


解决方案

请确保您正确导入监听器,你需要

 进口android.view.View.OnTouchListener;

在与其他进口文件的顶部。

i am loading an image from gallery through startActivityForResult() and loading the image in onActivity(). Can't i implement a touchlistener for that image? for reference see below.

protected void onActivityResult(int requestCode, int resultCode,
            Intent data) {
        if (requestCode == SELECT_PICTURE) {
        ...... 
        ...... 
          Bitmap bitmapPreview = BitmapFactory.decodeFile(fileSrc); //load preview image

         setimage.setImageBitmap(BitmapPreview);
     setimage.setOnTouchListener(new OnTouchListener() {

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        Toast.makeText(getApplicationContext(), "Image touced!", Toast.LENGTH_SHORT).show();
                        return true;
    }
    });

解决方案

Make sure that you imported the listener correctly, you need

import android.view.View.OnTouchListener;

at the top of your file with the other imports.

这篇关于setOnTouchlistener一个图像视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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