-1

I have a button "show" and when the button is clicked , the edit text box must not be editable and when I click next, I must give back the focus to edit text box. I tried the below code

  showans.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
               editText.setFocusable(false);
     }
  next.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            editText.setFocusable(true);
            editText.setClickable(true);
      }
 }

I tried changing values between setFocusable and setClickable but nothing helped. When I click the showans button for the first time, the edit box loses focus and its not clickable though I set the value to true when I click the "next" button and all these buttons .All these text boxes and buttons are dynamically generated.Any help would be great !! Thanks

Chirag Ghori
  • 4,231
  • 2
  • 20
  • 35
Anusha
  • 939
  • 3
  • 13
  • 31

4 Answers4

1

You can use

editText.setInputType(InputType.TYPE_NULL); for uneditable EditText 

and

editText.setInputType(InputType.TYPE_CLASS_TEXT) 

to make it editable
Uniruddh
  • 4,427
  • 3
  • 52
  • 86
Navin Gupta
  • 793
  • 6
  • 20
0

Please change to editText.requestFocus();

You can use editText.clearFocus();

Arshid KV
  • 9,631
  • 3
  • 35
  • 36
0

You can use setEnabled() method to disable or enable the editText

//to disable
editText.setEnabled(false);
//to re enable
editText.setEnabled(true);
Malith Lakshan
  • 762
  • 6
  • 12
0

You could try using setFocusableInTouchMode - so your code will change to something like this:

showans.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
               editText.setFocusable(false);
               editText.setFocusableInTouchMode(false);
     }
  next.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            editText.setFocusable(true);
            editText.setClickable(true);
            editText.setFocusableInTouchMode(true);
      }
 }

Give this a try and let me know if it helps.

ishmaelMakitla
  • 3,784
  • 3
  • 26
  • 32