我創建了一個對話框,無法在創建方法的主要活動中顯示它。 我喜歡這個調用對象的show
:無法顯示android對話框
FireMissilesDialogFragment newFragment = new FireMissilesDialogFragment();
newFragment.show();
,但我得到一個錯誤,指出它can't resolve method 'show'
這是我的對話框代碼(我正在學習如何使他們的,所以這是一個從Android開發人員網站對話框培訓複印件)
package com.shush;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
public class FireMissilesDialogFragment extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(R.string.name)
.setPositiveButton(R.string.name, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// FIRE ZE MISSILES!
}
})
.setNegativeButton(R.string.address, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User cancelled the dialog
}
});
// Create the AlertDialog object and return it
return builder.create();
}
}
什麼是擴展活動類從? – Harry