《Android權威編程》裡面的一道例題,
源代碼
package com.bignerdranch.android.criminalintent;
import android.app.AlertDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.widget.DatePicker;
public class DatePickerFragment extends DialogFragment {
/*View v = getActivity().getLayoutInflater()
.inflate(R.layout.dialog_date, null);*/
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
DatePicker dp = new DatePicker(getActivity());
return new AlertDialog.Builder(getActivity())
.setView(dp)
.setTitle(R.string.date_picker_title)
.setPositiveButton(android.R.string.ok, null)
.create();
}
}
顯示
代碼看起來沒有問題,你用手機試試,估計是模擬器才會出現的問題。