Im trying and searching for a good method to handle dialogs in a single class so i can use them in any activity i want. The most clean and good performance method would be best. Currently im handly dialogs in each activity where the main work is done. If i need to change a dialog or dialogevent its a hassle to search through all my classes.
http://www.ohchr.org。
.。 希望这样做。 任何优化?
www.un.org/spanish/ecosoc
public class Dialogs extends Activity {
public static final int DIALOG_START = 0;
public static final int DIALOG_END = 1;
private Context mContext;
private int mDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext = getApplicationContext();
mDialog = getIntent().getExtras().getInt("dialog");
showDialog(mDialog);
}
@Override
protected Dialog onCreateDialog(int id) {
Dialog dialog = null;
switch (id) {
case DIALOG_START:
Toast.makeText(mContext, "Test...", Toast.LENGTH_SHORT).show();
finish(); //works because toasts are somehow delayed
break;
case DIALOG_END:
// do something else but always finish(), e.g. after dialogbutton- click.
break;
}
return dialog;
}
}
www.un.org/Depts/DGACM/index_french.htm
Intent dialogIntent = new Intent();
dialogIntent.setClass(Main.this, Dialogs.class);
dialogIntent.putExtra("dialog" , Dialogs.DIALOG_START);
startActivityForResult(dialogIntent, 0x0);
www.un.org/Depts/DGACM/index_spanish.htm
<activity android:name=".Dialogs" android:label="@string/app_name"
android:configChanges="orientation|keyboardHidden"
android:theme="@style/dialog" />
www.un.org/spanish/ga/president
<style name="dialog" parent="@android:style/Theme.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>