英文易讀版
http://tinyurl.com/nqx48t7
私以為非常基本的東西:用對話盒來確認與使用者互動的流程
無奈遍巡資源後我所能做到的差強私意
主要是擴充 DialogFragment 和 implement NoticeDialogListener
這樣做我覺得流程來講實屬混亂 我了解流程本身可能是會混亂一點
因為對話盒是以主續之外的續來進行的; 但我希望能有一個更好的做法
來讓不同的對話盒有不同的回應 method 但我還沒找到該怎麼做
希望這樣的描述夠清楚 謝謝先
public class Confirm extends DialogFragment {
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(sQ);
builder
.setPositiveButton(sYes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
mListener.Yes();
}
})
.setNegativeButton(sNo, null);
return builder.create();
}
public interface NoticeDialogListener {
void Yes();
}
private NoticeDialogListener mListener;
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
mListener = (NoticeDialogListener) activity;
}
}
public class Main extends ActionBarActivity
implements Confirm.NoticeDialogListener {
...
private int iDialogMode;
private final static int DIALOG_ST_0 = 0;
private final static int DIALOG_ST_1 = DIALOG_ST_1 + 1;
private final static int DIALOG_ST_2 = DIALOG_ST_1 + 1;
@Override
public void Yes() {
switch (iDialogMode) {
case DIALOG_ST_0: // follow up HERE0 for what that dialog prompted
break;
case DIALOG_ST_1: // HERE1: feeling not smart
break;
case DIALOG_ST_2: // HERE2: believe there should be a better way
break;
}
}
public ... State_0_doing_something (...) {
...
Confirm diaBox = new Confirm (...);
iDialogMode = DIALOG_ST_0;
diaBox.show(getSupportFragmentManager(), "State_0");
// what's supposed to continue if confirmed will be followed up in HERE0 in Yes()
}
public ... State_1_doing_something_else (...) {
...
Confirm diaBox = new Confirm (...);
iDialogMode = DIALOG_ST_1;
diaBox.show(getSupportFragmentManager(), "State_2");
// what's supposed to continue if confirmed will be followed up in HERE1 in Yes()
}
public ... State_2_doing_yet_something_else (...) {
...
Confirm diaBox = new Confirm (...);
iDialogMode = DIALOG_ST_2;
diaBox.show(getSupportFragmentManager(), "State_3");
// what's supposed to continue if confirmed will be followed up in HERE2 in Yes()
}
}
我希望能讓不同的確認對話盒有不同的 click listener
而非像這樣用 *global* 變數/member 設定 dialog mode/state 來控制
懷念函數指標中