Blondy314
Blondy314

Reputation: 761

onClickListener for disabled edittext not called

I am trying to capture when an edittext field which is disabled gets pressed. (I only want to change it, I dont want text inserted into it). I assigned an onClickListener to it but it is not called.. Any suggestions ? Is there any other event I can listen to ?

final EditText field = column.get(i);
field.setEnabled(false);
field.setClickable(true);
field.setFocusable(false);
field.setFocusableInTouchMode(false);

field.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                ((EditText)v).setText("a");

            }
        });

Thanks !

Upvotes: 5

Views: 3556

Answers (2)

Niko
Niko

Reputation: 8153

final EditText field = column.get(i);
field.setCursorVisible(false);

field.setOnFocusChangeListener(new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                field.setText("something");
                field.clearFocus();
            }
        }
    });

Upvotes: 1

waqaslam
waqaslam

Reputation: 68177

You cant pass a click-event when a View is disabled.

Therefore, try changing:

field.setEnabled(false);

To:

field.setEnabled(true);

Upvotes: 5

Related Questions