0

I have an activity which has an EditText and a Button. The data in the EditText is not editable in the beginning, but it becomes editable when the Button is pressed.I have tried using android:editable="false" in the xml layout , but it is not working. Can somebody help me with this?

ebarrenechea
  • 3,775
  • 1
  • 31
  • 37
user47
  • 395
  • 1
  • 2
  • 16

3 Answers3

1
editText.setEnabled(true); or editText.setEnabled(false);

if cant works then Editable false

Community
  • 1
  • 1
Samir Mangroliya
  • 39,918
  • 16
  • 117
  • 134
1

You need to first set the TextEdit editable property to false in your xml layout :

<EditText
    ...
    android:id="@+id/input"
    android:clickable="false" />

And then when the button is clicked, set the TextEdit to editable :

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    input = (EditText) findViewById(R.id.input);
    button = (Button) findViewById(R.id.button);

    button.setOnClickListener(new View.OnClickListener()
    {
        public void onClick(View v)
        {
            input.setClickable(true);
        }

    });
}
Emmanuel Sys
  • 817
  • 6
  • 12
  • 1
    hey there is no setEditable() functions for the edit text fields.Hoew can I do it otherwise? – user47 May 31 '12 at 18:55
  • Oops. Unfortunately, `editable` property is only exposed through XML Programmatically, you should use either `setEnabled` or `setFocusable` or `setClickable`. However, when using these methods, you won't be able to select and copy the text... code updated. – Emmanuel Sys Jun 01 '12 at 19:02
0
<EditText
    ...
    android:id="@+id/urId"
    android:clickable="True" />

This worked for me, try your luck.

DjRaf
  • 3
  • 4