我創建了一個用於不同活動的AlertDialog片段。出於某種原因,警報不會被駁回,主要活動中的代碼不會繼續。我輸入了很多日誌命令來查看它到底停在哪裏。以下是我的提醒Dialog:AlertDialog沒有被解僱。
public class Convert_units_dialog extends DialogFragment {
final static String TAG = "TAG_convert_units";
public static Convert_units_dialog newInstance() {
Convert_units_dialog frag = new Convert_units_dialog();
Bundle args = new Bundle();
args.putInt("title", R.string.change_units_dialog);
frag.setArguments(args);
return frag;
}
public Dialog onCreateDialog(Bundle savedInstanceState) {
int title = getArguments().getInt("title");
return new AlertDialog.Builder(getActivity())
.setTitle(title)
.setPositiveButton(R.string.convert, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Log.i(TAG, "inside click listener");
convert_units();
//dismiss dialog here
Log.i(TAG, "Start dismiss");
dismiss();
Log.i(TAG, "End dismiss");
}
})
.setNegativeButton(R.string.dont_convert,null)
.create();
}
在我的活動中,我創建了一個調用alertDialog的函數。
private void open_alert_dialog() {
DialogFragment newFragment = Convert_units_dialog.newInstance();
newFragment.show(getFragmentManager(), "dialog");
Log.i(TAG,"open_alert_dialog finished");
}
當我運行我的代碼我得到「最終駁回」在日誌中再也看不到「open_alert_dialog完成」,所以按照我的活動這個命令的代碼沒有運行。有什麼明顯的我做錯了嗎?我已經嘗試了很多我見過的建議,但目前還沒有任何建議。
我對編程有點新,一般會感激任何輸入。謝謝。
當您點擊正面按鈕時,您的應用程序崩潰了嗎? 您應該在崩潰時複製/粘貼logcat。 – PAD