android - 使用先前选择的值开始数字选择器

标签 android android-alertdialog android-number-picker

我正在使用警报 dailog 作为数字选择器,我能够选择值并将其设置为我的 TextView ,但我正在尝试的是,如果我从数字选择器中选择假设 5,那么它将设置为 TextView ,如果我点击 textview 然后 5 必须被聚焦或选择到 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); 

关于android - 使用先前选择的值开始数字选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38781024/

相关文章:

Android Wear - 通知背景使用指定的纯色

android - 在 Fragment 中创建 AlarmDialog

android - 在 NumberPicker 中显示更多数字

android - 使用 ScrollViews 布局到 Horizo​​ntalScrollView

android - Flutter:应用程序在热重载后不断回到初始路线

Android:减少处理 AlertDialog 的代码

android - 如何为 AlertDialog 创建 setAdapter()

java - 在水平模式下创建一个数字选择器,android :orientation ="horizontal" work? 我试过但数字选择器在垂直模式下仍然相同

android - 带加号 (+) 字符的 Android 数字键盘

android - 如何在 Android 线性布局中使按钮覆盖全屏宽度?