How to disable click listener in image view

I am working on an android application in which I make a click listener when viewing images. I just want to disable the image listener, for example, I have an edit button, without clicking the edit button.

image = (ImageView) findViewById(R.id.image); editText.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (clickCount == 0) { Toast.makeText(getApplicationContext(), "Enabled", Toast.LENGTH_SHORT).show(); fName.setEnabled(true); lName.setEnabled(true); mailText.setEnabled(true); mobileText.setEnabled(true); mCond.setEnabled(true); mNotes.setEnabled(true); medication.setEnabled(true); alReact.setEnabled(true); dofo.setEnabled(true); image.setEnabled(true); editText.setText("Done"); clickCount = 1; } else if (clickCount == 1) { Toast.makeText(getApplicationContext(), "Done", Toast.LENGTH_SHORT).show(); fName.setEnabled(false); lName.setEnabled(false); mailText.setEnabled(false); mobileText.setEnabled(false); meond.setEnabled(false); mNotes.setEnabled(false); meation.setEnabled(false); alReact.setEnabled(false); doInfo.setEnabled(false); image.setEnabled(false); editText.setText("Edit"); updatingUser(); clickCount = 0; } } }); 
+6
source share
5 answers

just add it to the onCreate method

image.setEnabled(false);

+24
source

If you want to clear the onClick imageView listener. Just call

 myImageView.setOnClickListener(null); 

Hope this helps.

Update: The "advantage" (depending on what you need) setOnClickListener is null, so it will not change the background of the button, as in setClickable (false) or setEnabled (false).

Because the button wants to show the user if he is on (false) or setClickable (false).

If you do not want this, just use my answer. :) I hope this helps and gives the direction of what you want

+3
source

Use image.setClickable (false) to provide feedback on viewing images. try it

  image = (ImageView) findViewById(R.id.image); image.setClickable(false); editText.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { image.setClickable(true); } 

Hope this helps you friend :)

+2
source

Use this line in your XML:

 android:clickable="false" 
+2
source

Try the following:

 image.setClickable(false); 
0
source

Source: https://habr.com/ru/post/978860/


All Articles