Android ImageView's onClickListener does not work

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

    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); 
    

提交回复
热议问题