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
Check if other view has the property match_parent
or fill_parent
,those properties may cover your ImageView
which has shown in your RelativeLayout
.By the way,the accepted answer does not work in my case.
Please Try this one.
ImageView imageview1 = findViewById(R.id.imageView1);
imageview1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(YourActivity.this, "Here is your Text",Toast.LENGTH_SHORT).show();
}
});
As a beginner to android development, my issue wasn't any of these solutions. I had several problems.
Firstly, I didn't realise that you had to use the bug symbol to use the debugger to hit breakpoints.
Then I was silently getting an error in my on click listener, I was trying to pass something to a method, but the method required a float value.
However in the ide, the method was shown as unused. It wasn't until I cast the value that the method was shown in the correct colour and wasn't marked as unused anymore.
Not sure why I didn't get an error from trying to use a method with the wrong type ?
Also I had to add the android:debuggable="true"
to my manifest to get debugging to hit breakpoints.