解决方案是 onCreatDialog。关于崩溃的另一个问题是由我的 listView xml 中的 LinearLayout 父级引起的
这是我的代码[编辑]:
public class MyDialogFragment extends DialogFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View mView = inflater.inflate(R.layout.fragment_dialog, null);
ListView mListView = (ListView) mView.findViewById(R.id.lvListe);
String[] mValues = {"Orientation", "Nombre de Chambres", "Nombre de Salle de bains", "Nombre de toilettes", "Cave", "Parking", "Garage", "Jardin"};
getDialog().setTitle("Autres Critères");
mListView.setAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, mValues));
return mView;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(getActivity())
.setPositiveButton("ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
}
)
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
onCancel(dialog);
}
}
)
.create();
}
}
提前致谢 :)