Reputation: 32243
I have a little problem. In my program I defined
protected Dialog onCreateDialog(int id) {
if (id == CONTEXT_MENU_ID) {
return createMyDialog();
}
return super.onCreateDialog(id);
}
and then show the dialog calling
showDialog(CONTEXT_MENU_ID)
My problem is that sometimes I want to change the texts of the Dialog dynamically between executions. But with that method the Dialog is never recreated. How can I make the createMyDialog() to be called before showing the Dialog?
Thanks
Upvotes: 2
Views: 1683
Reputation: 8935
If you want to change dialog settings (text, etc.) you need to do it in onPrepareDialogMethod it will be called each time you call showDialog
method
Upvotes: 5
Reputation: 31779
This might be worth a try. I haven't tested it out. To the dialog if you set the textview as its content, then you can set an id to it.
TextView text = new TextView(this);
ViewGroup.LayoutParams vp = new ViewGroup.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
text.setLayoutParams(vp);
text.setText("HI");
text.setId(1005);
dialog.setContentView(text);
So the next time when you try to update the textview, you might be able to access it using the id.
((TextView)dialog.getWindow().getDecorView().findViewById(1005))
.setText("New Text");
Upvotes: 0