當用戶打開NumberPicker時是否可以顯示某個值?例如,我有最小值= 10,最大值= 50;在NumberPicker中顯示特定值
final NumberPicker picker = new NumberPicker(MonitorActivity.this);
picker.setMinValue(10);
picker.setMaxValue(50);
當NumberPicker被打開,我想表明值= 30,而不是10非標準我 如何才能做到這一點?
UPDATE:
upTv = (TextView) findViewById(R.id.upper_tv);
upTv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
show(180, 200, upTv);
}
});
public void show(int int1, int int2, final TextView tv)
{
String button1String = "OK";
String button2String = "cancell";
ad = new AlertDialog.Builder(MonitorActivity.this);
ad.setTitle("Title");
final NumberPicker picker = new NumberPicker(MonitorActivity.this);
picker.setMinValue(int1);
picker.setMaxValue(int2);
picker.setWrapSelectorWheel(false);
final FrameLayout parent = new FrameLayout(MonitorActivity.this);
parent.addView(picker, new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT,
Gravity.CENTER));
ad.setView(parent);
ad.setPositiveButton(button1String, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int arg1) {
int pickedValue = picker.getValue();
tv.setText(String.valueOf(picker.getValue()));
picker.setValue(pickedValue);
}
});
ad.setNegativeButton(button2String, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int arg1) {
}
});
ad.setCancelable(true);
ad.show();
}
揀出器是對話框裏面?請發佈完整的代碼。 –
@NigamPatro添加了 – MrStuff88
這裏的問題是,你沒有設置顯示時的優點。您需要在setMaxValue()之後將默認值傳遞給show()和setValue(); –