gpt4 book ai didi

android - 如何在 DialogFragment 中设置肯定/否定按钮?

转载 作者:搜寻专家 更新时间:2023-11-01 08:02:58 25 4
gpt4 key购买 nike

解决方案是 onCreatDialog。关于崩溃的另一个问题是由我的 listView xml 中的 LinearLayout parent 引起的

这里是我的代码[已编辑]:

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();
}

}

提前致谢:)

最佳答案

请看一下DialogFragmentcreateDialog()方法。

这是一个例子:

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

return new AlertDialog.Builder(getActivity())
.setTitle("Title")
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// DO SOMETHING
}
}
)
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// DO SOMETHING
}
}
)
.create();
}

关于android - 如何在 DialogFragment 中设置肯定/否定按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18405241/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com