Android AlertDialog with dynamically changing text on every request

Posted by Ulrich Scheller on Stack Overflow See other posts from Stack Overflow or by Ulrich Scheller
Published on 2009-06-05T07:52:49Z Indexed on 2010/06/06 1:12 UTC
Read the original article Hit count: 333

Filed under:
|

I want to show an AlertDialog with one option that might change on every request. So for example at one time I want to show the option "add to contacts" while another time it should be "remove from contacts".

My code does work on the first time, however Android seems to cache the AlertDialog so that onCreateDialog is not executed next time. Therefore the option doesnt change anymore. Can I prevent this caching, or is there just another way of changing the option?

I am working with SDK 1.5 but using 1.1.

@Override
protected Dialog onCreateDialog(final int id) {
    ...
    String add_remove_contact = res.getString(R.string.profile_add_to_contacts);
	if (user.getContacts().contains(profileID)) {
    	add_remove_contact = res.getString(R.string.profile_remove_from_contacts);
    	// TODO: this string is not changed when contact status changes 
    }
    final CharSequence[] items = {res.getString(R.string.view_profile),
								  res.getString(R.string.profile_send_message),
								  add_remove_contact};
	AlertDialog.Builder builder = new AlertDialog.Builder(this);
	...
	return builder.create();
}

© Stack Overflow or respective owner

Related posts about java

Related posts about android