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.
F
The same thing is happening for me.
The reason is: I have used a list view with margin Top so the data is starting from the bottom of the image, but the actual list view is overlapping on the image which is not visible. So even if we click on the image, the action is not performed. To fix this, I have made the list view start from the below the image so that it is not overlapping on the image itself.
can you Try this and tell me what happens ?? :
ImageView imgFavorite = (ImageView) findViewById(R.id.favorite_icon);
imgFavorite.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(YourActivityName.this,
"The favorite list would appear on clicking this icon",
Toast.LENGTH_LONG).show();
}
});
or you should add this :
imgFavorite.setClickable(true);
Actually I just used imgView.bringToFront();
and it helped.
Had the same problem, thanks for the Framelayout tip! I was using two overlapped images in a framelayout (the one at top was an alpha mask, to give the effect of soft borders)
I set in the xml android:clickable="true"
for the image I wanted to launch the onClickListener, and android:clickable="false"
to the alpha mask.
For inner classes to pass the reference of activity, I usually create a reference of activity in onCreate() and make it as a member. As inner classes have access to members of parent class you can get hold of your activity and thus its context:
class MyClass extends Activity{
private Activity thisActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
thisActivity = this;
}
}
Hope that helps.
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 Toast
as well as the Log
.
Thank you everybody for taking time to solve the issue.. Was surely tricky..