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?
Asked
Active
Viewed 597 times
0

ebarrenechea
- 3,775
- 1
- 31
- 37

user47
- 395
- 1
- 2
- 16
3 Answers
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
-
1hey 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.

S.L. Barth is on codidact.com
- 8,198
- 71
- 51
- 66

DjRaf
- 3
- 4
-
-
Welcome to Stack Overflow! I've edited your answer. If you want to show code here, you should indent it by 4 spaces. This automatically puts a line in `code markdown`. – S.L. Barth is on codidact.com Feb 26 '16 at 10:12