使用先前选择的值开始数字选择器
start number picker with previously selected value
我正在使用警报 dailog 作为数字选择器,我能够 select 值并将其设置到我的文本视图,但我正在尝试的是,如果我 select 假设数字选择器中有 5 ,然后它将设置为 textview,如果我再次单击 textview,则必须聚焦 5 或 selected 到 numberpicker
public void qtyshow()
{
final AlertDialog.Builder alert = new AlertDialog.Builder(ProductView.this);
alert.setTitle("Select the Qty: ");
final NumberPicker np = new NumberPicker(ProductView.this);
np.setMaxValue(20); // max value 20
np.setMinValue(1); // min value 0
np.setWrapSelectorWheel(false);
alert.setView(np);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
proqty.setText(String.valueOf(np.getValue())); //set the value to textview
// Do something with value!
Float mulprice=Float.parseFloat(packlist.get(0).getProductPack_SP());
int mulqty= np.getValue();
Float total=mulprice*mulqty;
packsp.setText("$" + String.format("%.2f%n", total));
System.out.println("price test" + packlist.get(0).getProductPack_SP() + "," + mulprice + "," + mulqty + "," + String.format("%.2f%n", total));
Float mulelseprice=Float.parseFloat(packlist.get(0).getProductPack_ElseWhere());
Float totalelse=mulelseprice*mulqty;
packelsewhere.setText("$" + String.format("%.2f%n", totalelse));
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Cancel.
}
});
alert.show();
}
你可以这样做:
mNumberPicker.setValue(number);
我正在使用警报 dailog 作为数字选择器,我能够 select 值并将其设置到我的文本视图,但我正在尝试的是,如果我 select 假设数字选择器中有 5 ,然后它将设置为 textview,如果我再次单击 textview,则必须聚焦 5 或 selected 到 numberpicker
public void qtyshow()
{
final AlertDialog.Builder alert = new AlertDialog.Builder(ProductView.this);
alert.setTitle("Select the Qty: ");
final NumberPicker np = new NumberPicker(ProductView.this);
np.setMaxValue(20); // max value 20
np.setMinValue(1); // min value 0
np.setWrapSelectorWheel(false);
alert.setView(np);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
proqty.setText(String.valueOf(np.getValue())); //set the value to textview
// Do something with value!
Float mulprice=Float.parseFloat(packlist.get(0).getProductPack_SP());
int mulqty= np.getValue();
Float total=mulprice*mulqty;
packsp.setText("$" + String.format("%.2f%n", total));
System.out.println("price test" + packlist.get(0).getProductPack_SP() + "," + mulprice + "," + mulqty + "," + String.format("%.2f%n", total));
Float mulelseprice=Float.parseFloat(packlist.get(0).getProductPack_ElseWhere());
Float totalelse=mulelseprice*mulqty;
packelsewhere.setText("$" + String.format("%.2f%n", totalelse));
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Cancel.
}
});
alert.show();
}
你可以这样做:
mNumberPicker.setValue(number);