i'm stuck whit a very strange problem. I have an editText in a dialog. If I open the dialog one time (tapping on a element of a ListView) and do some stuff all ok. If I open the dialog the next time (tapping on a different element of a ListView) the editText display the same value of the first time.
toast(profilesList.get(toEdit).get(NAME).toString()); //toast say Bob
et_profileName.setText(profilesList.get(toEdit).get(NAME).toString()); //I see Alice
Another strange thing: if I rotate the display the text change in "BobAlice". If I close the dialog, and then I reopen it, all work well and the dialog display the right Strings.
Any suggestions?
EDIT: et_profileName is in a dialog tha开发者_运维技巧t opens when you click an item in the ListView.
More code:
protected Dialog onCreateDialog(int id) {
dialog = new Dialog(this);
...
et_profileName= (EditText)dialog.findViewById(R.id.et_profileName);
...
}
Here is when I call the dialog:
showDialog(DIALOG_EDIT_PROFILE);
toast(profilesList.get(toEdit).get(NAME).toString());
et_profileName.setText(profilesList.get(toEdit).get(NAME).toString());
Also don't work if I put
et_profileName= (EditText)dialog.findViewById(R.id.et_profileName);
before the et_profileName.setText(...)
SOLVED:
Should override the onPrepareDialog(int id, Dialog dialog)
to prepare a
managed dialog before it is being shown.
Added this code, it works:
@Override
protected void onPrepareDialog(int id, Dialog dialog){
et_profileName= (EditText)dialog.findViewById(R.id.et_profileName);
if(id==DIALOG_EDIT_PROFILE){
et_profileName.setText(profilesList.get(toEdit).get(NAME).toString());
}
}
Thanks you all!
精彩评论