setText doesn't set text to EditText
onActivityResult()
is not the last method called when returning to an Activity. You can refresh your memory of the Life Cycle in the docs. :)
As we discussed in the comments, if you call setText()
again in methods like onResume()
this will override any text set in onActivityResult()
.
The same goes for Fragments, you need to make updates in onViewStateRestored() method (which was added in API 17).
Some times changing edittext
in onactivity
result is not working. I too faced the same problem
instead of setting
edittext.settext("yourtext");
change to following in onactivityresult
edittext.post(new Runnable(){
edittext.settext("yourtext");
});
It worked for me.
First of all you have to debug this.
There is a class called TextWatcher. This will be called every time your Textbox.Text will change. So this is easier to debug and handle the problem. Url: http://developer.android.com/reference/android/text/TextWatcher.html
Example for implementation:
name.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
doSomething();
}
});
Good luck :)