在 AlertDialog 上显示 NumberPicker
Display a NumberPicker on an AlertDialog
我正在尝试在 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();
}
您从未设置对话框的视图。
builder.setView(numberPicker);
您需要包括 2 行:
builder.setView(numberPicker);
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();
}
我正在尝试在 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();
}
您从未设置对话框的视图。
builder.setView(numberPicker);
您需要包括 2 行:
builder.setView(numberPicker);
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();
}