Android ImageView's onClickListener does not work

前端 未结 15 1751
情话喂你
情话喂你 2020-12-01 13:30

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

相关标签:
15条回答
  • 2020-12-01 14:24

    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.

    0 讨论(0)
  • 2020-12-01 14:30

    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();
    
            }
    
        });
    
    0 讨论(0)
  • 2020-12-01 14:32

    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.

    0 讨论(0)
提交回复
热议问题