gpt4 book ai didi

java - 如何让选号器不可取消?

转载 作者:行者123 更新时间:2023-12-02 09:06:00 26 4
gpt4 key购买 nike

如何让Android中的数字选择器不可取消?这是我的代码:

public static class NumberPickerDialog extends DialogFragment
{
private NumberPicker.OnValueChangeListener valueChangeListener;
int min, max, current;
String title;

NumberPickerDialog(int min, int max, String title, int current)
{
this.min = min;
this.max = max;
this.title = title;
this.current = current;
}

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{

final NumberPicker numberPicker = new NumberPicker(getActivity());

numberPicker.setMinValue(min);
numberPicker.setMaxValue(max);
numberPicker.setValue(current);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(title);
builder.setCancelable(false); //this doesn't work
builder.setPositiveButton("OK", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
valueChangeListener.onValueChange(numberPicker,
numberPicker.getValue(), numberPicker.getValue());
}
});


builder.setView(numberPicker);
return builder.create();
}

void setValueChangeListener(NumberPicker.OnValueChangeListener valueChangeListener)
{
this.valueChangeListener = valueChangeListener;
}
}

如何设置此对话框在用户不选择号码时始终处于 Activity 状态?可取消选项适用于其他格式,但不适用于数字选择器。组件有问题吗?

最佳答案

new NumberPickerDialog().setCancelable(false);

关于java - 如何让选号器不可取消?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59806230/

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