好的我想显示这个AlertDialog,但我只得到一个没有消息或按钮的空白区域。有人知道出了什么问题吗?这是我的主要课程,包括对话框:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void CreateDialog1(View view){
final DialogFragment DFragment1=new DialogFragment();
DFragment1.show(getFragmentManager(), "Alarm1");
AlertDialog.Builder builder = new AlertDialog.Builder(getApplication());
builder.setMessage(R.string.create_alarm1);
builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent1 = new Intent(AlarmClock.ACTION_SET_ALARM)
.putExtra(AlarmClock.EXTRA_MESSAGE, "You have set an alarm for the first hour at 6:30 AM")
.putExtra(AlarmClock.EXTRA_HOUR, 6)
.putExtra(AlarmClock.EXTRA_MINUTES, 30);
}
if (intent1.resolveActivity(getPackageManager()) != null) {
startActivity(intent1);
DFragment1.dismiss();
}
}
});
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
DFragment1.getDialog().cancel();
}
});AlertDialog dialog1=builder.create();
}
答案 0 :(得分:0)
你需要在构建后显示它,添加:
dialog1.show();