Usman Khan
Usman Khan

Reputation: 3973

How to disable click listener on image view android

I am working on android application in which i am making click listener on image view. I just want to disable image listener, for example i have a edit button , without clicking edit button image view listener should be disabled.

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

Upvotes: 15

Views: 53691

Answers (5)

Deepak Singh
Deepak Singh

Reputation: 154

Try This:

image.setClickable(false); 

Upvotes: 5

Nazmus Saadat
Nazmus Saadat

Reputation: 973

Use this line into your XML:

android:clickable="false"

Upvotes: 7

user4272989
user4272989

Reputation:

Use image.setClickable(false) to set imageview clickable disable try this

 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 will help you friend :)

Upvotes: 3

Mike
Mike

Reputation: 857

If you want To clear the onClick-listenener of the imageView. Simply call

myImageView.setOnClickListener(null);

Hope it helps.

Update: "Advantage" (depends on what you want") of setOnClickListener to null is that it will not change the background of the button like it does at setClickable(false) or setEnabled(false).

Because the button wants to show the user if he is in an enabled(false) or setClickable(false) mode.

If you don't want that, simply use my answere. :) hope it helps and gives a direction of what you want

Upvotes: 5

Prashant Jajal
Prashant Jajal

Reputation: 3627

just add it in onCreate Method

image.setEnabled(false);

Upvotes: 51

Related Questions