安卓的ImageView onClickListener不起作用 [英] Android ImageView's onClickListener does not work

查看:1866
本文介绍了安卓的ImageView onClickListener不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我想要实现的onClickListener一个ImageView的。但是,当我点击图片,没有任何反应。事件的logcat不显示任何错误。

I have an ImageView for which I wanted to implement the onClickListener. But when I click on the image, nothing happens. Event the Logcat does not show any errors.

以下是我import语句:

Following is my import statement:

import android.view.View.OnClickListener;

以下是我的布局code为图像:

Following is my layout code for the image:

<ImageView android:id="@+id/favorite_icon" 
    android:src="@drawable/small_star"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="top|right" android:paddingTop="63sp"
    android:paddingRight="2sp"  />

以下是code。在我的活动中定义的事件处理程序onClickListener:

Following is the code in my activity which defines the event handler for onClickListener:

ImageView imgFavorite = (ImageView) findViewById(R.id.favorite_icon);
imgFavorite.setClickable(true);
imgFavorite.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i(SystemSettings.APP_TAG + " : " + HomeActivity.class.getName(), "Entered onClick method");
                Toast.makeText(v.getContext(),
                        "The favorite list would appear on clicking this icon",
                        Toast.LENGTH_LONG).show();
            }
        });

我缺少的东西。任何帮助将是AP preciated。

Am I missing something. Any help would be appreciated.

在此先感谢。

推荐答案

好了,

我设法解决这个棘手的问题。事情就像我用的FrameLayout 。不知道为什么,但它来到我的脑海里,可能是该图标会得到隐藏在其他一些观点。

I managed to solve this tricky issue. The thing was like I was using FrameLayout. Don't know why but it came to my mind that may be the icon would be getting hidden behind some other view.

我试图把图标我的布局的结束,现在我能看到吐司还有登录

I tried putting the icon at the end of my layout and now I am able to see the Toast as well as the Log.

感谢您大家抽出时间来解决这个问题..当时确实非常棘手。

Thank you everybody for taking time to solve the issue.. Was surely tricky..

这篇关于安卓的ImageView onClickListener不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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