I have a programmatically view with an EditText as a main feature. I need to be able to edit back the contents on it, but whenever i click the EditText everything gets deleted. How can i avoid everything being deleted on the EditText when the user back to edit it?(the user enters some other view in the same activity, and then go back to edit the contents on the Edit text)
For others functionalities i have TextWatcher implemented.
Where should i look to change this behaviour (look the image please)? I though that on the text watcher could change this, but i'm out ideas.
class CoolEditText{
textField = new EditText(c);
textField.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
textField.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
textField.setLongClickable(false);
textField.setTextIsSelectable(false);
//more init here...
textField.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
//some code needed
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
//some code needed
}
@Override
public void afterTextChanged(Editable editable) {
//some code needed
}//....
Already solved:
Already solved this. The default or common behavior of Android's EditText is allow edit it's contents. On my problem i have an instance of CoolEditText somewhere else in the code where onFocusChange was implemented and assigned to that instance. So inside the onFocusChage the mText value was being reset to empty string.
class AnotherClass{
CoolEditText te = new CoolEditText();//...
te.setOnFocusChangeListener(new OnFocusChangeListener(){
@Override
public void onFocusChange(View view, boolean hasFocus) {
if(!te.equals("")){
te.setText(""); //i just delete this
}
}
});
So, briefing, EditText allows by default edit the contents inside, to change this behavior you should assign an OnFocusChangeListener
and overwrite onFocusChange
where you can change this behavior.