Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 !

like image 681
Blondy314 Avatar asked Sep 26 '12 12:09

Blondy314


2 Answers

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

Therefore, try changing:

field.setEnabled(false);

To:

field.setEnabled(true);
like image 113
waqaslam Avatar answered Oct 26 '22 22:10

waqaslam


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();
            }
        }
    });
like image 26
Niko Avatar answered Oct 26 '22 23:10

Niko