gpt4 book ai didi

android - 在 AlertDialog 上显示 NumberPicker

转载 作者:太空宇宙 更新时间:2023-11-03 12:28:47 25 4
gpt4 key购买 nike

我正在尝试在 AlertDialog 上显示 NumberPicker。
AlertDialog 有效,但它不显示 NumberPicker。

这是我的代码

public Dialog onCreateDialog(Bundle savedInstanceState){
final NumberPicker numberPicker = new NumberPicker(getActivity());
numberPicker.setMaxValue(360);
numberPicker.setMinValue(0);


AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Changing the Hue");
builder.setMessage("Choose a value :");
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
dialogHost.onPositiveButton(numberPicker.getValue());
}
});
builder.setNegativeButton("CANCEL", new DialogInterface.OnClickListener(){

@Override
public void onClick(DialogInterface dialog, int which) {
dialogHost.onCancelButton();
}
});
return builder.create();
}

最佳答案

你需要包括两行:

  1. builder.setView(numberPicker);
  2. return build.show()

所以,代码必须是这样的:

public Dialog onCreateDialog(Bundle savedInstanceState)
{
final NumberPicker numberPicker = new NumberPicker(getActivity());
numberPicker.setMaxValue(360);
numberPicker.setMinValue(0);


AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setView(numberPicker);
builder.setTitle("Changing the Hue");
builder.setMessage("Choose a value :");
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which)
{
dialogHost.onPositiveButton(numberPicker.getValue());
}
});
builder.setNegativeButton("CANCEL", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
dialogHost.onCancelButton();
}
});
builder.create();
return builder.show();
}

关于android - 在 AlertDialog 上显示 NumberPicker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40162539/

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