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.
Following is my import statement:
import android.view.View.OnClickListener;
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" />
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();
}
});
Am I missing something?
Ok,
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
Toastas well as theLog.Thank you everybody for taking time to solve the issue.. Was surely tricky..