我正在尝试使用 DialogFragment 创建一个弹出窗口,但是我的对话框仅包含标题、否定和肯定按钮。布局选择对话框<Button android:text="Aalborg" android:layout_width="200dp" android:layout_height="wrap_content" android:id="@+id/firstCityBtn" app:layout_constraintStart_toStartOf="parent"/><Button android:text="Aarhus" android:layout_width="200dp" android:layout_height="wrap_content" android:id="@+id/thirdCityBtn" app:layout_constraintBottom_toBottomOf="parent"/><Button android:text="København" android:layout_width="200dp" android:layout_height="wrap_content" android:id="@+id/secondCityBtn" android:layout_marginTop="8dp"/>选择对话框public class SelectionDialog extends DialogFragment { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); LayoutInflater inflater = getActivity().getLayoutInflater(); View view = inflater.inflate(R.layout.layout_selection_dialog, null); builder.setTitle("Vælg by").setNegativeButton("Back", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { } }).setPositiveButton("Save", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { } }); return builder.create(); }}在 MainActivity 中调用的函数fun showCitySelection() { var dialog: CitySelectionDialog = CitySelectionDialog() var ft: FragmentTransaction = supportFragmentManager.beginTransaction() dialog.show(ft, null)}任何想法为什么我没有在对话框中获得我的按钮?
添加回答
举报
0/150
提交
取消