Reputation: 1567
I have a user profile screen in my android app and there i am showing user information while registering they provided and a edit button to modify their information.
Upvotes: 7
Views: 18610
Reputation: 473
android:editable is deprecated.
Use only android:focusable="false"
in xml.
And on button click -
EditText editText = findViewById(R.id.yourid);
editText.setFocusableInTouchMode(true);
Upvotes: 0
Reputation: 670
You can use this code : It handles edit and done both events.
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private EditText edtText;
private Button btnEdit;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edtText = findViewById(R.id.edtTxt);
btnEdit = findViewById(R.id.btnEdt);
edtText.setEnabled(false);
btnEdit.setText("Edit");
btnEdit.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnEdt: //Your edit button
enableDisableEditText();
break;
default:
break;
}
}
//method for enable or disable edittext
private void enableDisableEditText() {
if (edtText.isEnabled()) {
edtText.setEnabled(false);
btnEdit.setText("Edit");
} else {
edtText.setEnabled(true);
btnEdit.setText("Done");
}
}
}
Happy coding..
Upvotes: 0
Reputation: 3406
edT.setFocusable(false); //to disable it
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
edT.setFocusableInTouchMode(true); //to enable it
}
});
Upvotes: 5
Reputation: 3338
You can disable it in your xml
android:editable="false"
android:inputType="none"
And enable it programatically in the onClick()
of the edit Button
EditText mEdit = (EditText) findViewById(R.id.yourid);
mEdit.setEnabled(true);
Upvotes: 6