Android ImageView's onClickListener does not work

前端 未结 15 1818
情话喂你
情话喂你 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:18

    Add android:onClick="clickEvent" to your image view.

    
    

    In your activity you can create a method with the same name (clickEvent(View v)), and that's it! You can see the log and the toast text too.

    public void clickEvent(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();
      }
    

提交回复
热议问题