解决方法
如果您正在使用
Android 2.2(API 8级或更高版本)
public final boolean showDialog (int id,Bundle args)
并在Bundle中传递你的观点.见documentation.
如果您想支持较旧的Android版本,您应该将参数保存在Activity类成员中,然后从onPrepareDialog
功能中访问它们.请注意,onCreateDialog
将不适合您的需求,因为它仅用于创建对话框.
class MyActivity { private static int MY_DLG = 1; private String m_dlgMsg; private showMyDialog(String msg){ m_dlgMsg = msg; showDialog(MY_DLG); } private doSomething() { ... showMyDlg("some text"); } protected void onCreateDialog(int id){ if(id == MY_DLG){ AlertDialog.Builder builder = new AlertDialog.Builder(this); .... return builder.create(); } return super.onCreateDialog(id); } @Override protected void onPrepareDialog (int id,Dialog dialog){ if(id == MY_DLG){ AlertDialog adlg = (AlertDialog)dialog; adlg.setMessage(m_dlgMsg); } else { super.onPrepareDialog(id,dialog); } } }