<small id='jk2Qv'></small><noframes id='jk2Qv'>

<legend id='jk2Qv'><style id='jk2Qv'><dir id='jk2Qv'><q id='jk2Qv'></q></dir></style></legend>

    • <bdo id='jk2Qv'></bdo><ul id='jk2Qv'></ul>

      <tfoot id='jk2Qv'></tfoot>
    1. <i id='jk2Qv'><tr id='jk2Qv'><dt id='jk2Qv'><q id='jk2Qv'><span id='jk2Qv'><b id='jk2Qv'><form id='jk2Qv'><ins id='jk2Qv'></ins><ul id='jk2Qv'></ul><sub id='jk2Qv'></sub></form><legend id='jk2Qv'></legend><bdo id='jk2Qv'><pre id='jk2Qv'><center id='jk2Qv'></center></pre></bdo></b><th id='jk2Qv'></th></span></q></dt></tr></i><div id='jk2Qv'><tfoot id='jk2Qv'></tfoot><dl id='jk2Qv'><fieldset id='jk2Qv'></fieldset></dl></div>
    2. 如何在对话框中使用数字选择器

      时间:2023-08-31

      <i id='seOT3'><tr id='seOT3'><dt id='seOT3'><q id='seOT3'><span id='seOT3'><b id='seOT3'><form id='seOT3'><ins id='seOT3'></ins><ul id='seOT3'></ul><sub id='seOT3'></sub></form><legend id='seOT3'></legend><bdo id='seOT3'><pre id='seOT3'><center id='seOT3'></center></pre></bdo></b><th id='seOT3'></th></span></q></dt></tr></i><div id='seOT3'><tfoot id='seOT3'></tfoot><dl id='seOT3'><fieldset id='seOT3'></fieldset></dl></div>
      <legend id='seOT3'><style id='seOT3'><dir id='seOT3'><q id='seOT3'></q></dir></style></legend>

          <bdo id='seOT3'></bdo><ul id='seOT3'></ul>

          <small id='seOT3'></small><noframes id='seOT3'>

            <tbody id='seOT3'></tbody>

            • <tfoot id='seOT3'></tfoot>
                本文介绍了如何在对话框中使用数字选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我想使用数字选择器从用户那里获得折扣百分比.一旦用户输入销售价格,我希望出现一个对话框询问折扣百分比.我找不到将数字选择器集成到对话框中的方法.

                I want to use a number picker for the purpose of getting the discount percentage from the user. once the user enters the sale price, i want a dialog box to appear asking for the discount percentage. I cannot find a way to integrate the numberpicker in the dialog.

                推荐答案

                我做了一个NumberPicker的小demo.这可能并不完美,但您可以使用和修改它.

                I have made a small demo of NumberPicker. This may not be perfect but you can use and modify the same.

                使用自定义对话框并设置数字选择器.

                Use a custom dialog and set the number picker.

                更多信息@

                http://developer.android.com/reference/android/widget/NumberPicker.html

                public class MainActivity extends Activity implements NumberPicker.OnValueChangeListener
                {
                    private TextView tv;
                    static Dialog d ;
                    @Override
                    public void onCreate(Bundle savedInstanceState)
                    {
                        super.onCreate(savedInstanceState);
                        setContentView(R.layout.activity_main);
                        tv = (TextView) findViewById(R.id.textView1);
                        Button b = (Button) findViewById(R.id.button11);// on click of button display the dialog
                         b.setOnClickListener(new OnClickListener()
                         {
                
                            @Override
                            public void onClick(View v) {
                                 show();
                            }
                            });
                           }
                    @Override
                    public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
                
                         Log.i("value is",""+newVal);
                
                     }
                
                    public void show()
                    {
                
                         final Dialog d = new Dialog(MainActivity.this);
                         d.setTitle("NumberPicker");
                         d.setContentView(R.layout.dialog);
                         Button b1 = (Button) d.findViewById(R.id.button1);
                         Button b2 = (Button) d.findViewById(R.id.button2);
                         final NumberPicker np = (NumberPicker) d.findViewById(R.id.numberPicker1);
                         np.setMaxValue(100); // max value 100
                         np.setMinValue(0);   // min value 0
                         np.setWrapSelectorWheel(false);
                         np.setOnValueChangedListener(this);
                         b1.setOnClickListener(new OnClickListener()
                         {
                          @Override
                          public void onClick(View v) {
                              tv.setText(String.valueOf(np.getValue())); //set the value to textview
                              d.dismiss();
                           }    
                          });
                         b2.setOnClickListener(new OnClickListener()
                         {
                          @Override
                          public void onClick(View v) {
                              d.dismiss(); // dismiss the dialog
                           }    
                          });
                       d.show();
                
                
                    }
                }
                

                activity_main.xml

                activity_main.xml

                <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                    xmlns:tools="http://schemas.android.com/tools"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    tools:context=".MainActivity" >
                
                    <TextView
                        android:id="@+id/textView1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/hello_world" />
                
                    <Button
                        android:id="@+id/button11"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentBottom="true"
                        android:layout_centerHorizontal="true"
                        android:text="Open" />
                
                </RelativeLayout>
                

                dialog.xml

                <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent" >
                
                    <NumberPicker
                        android:id="@+id/numberPicker1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentTop="true"
                        android:layout_centerHorizontal="true"
                        android:layout_marginTop="64dp" />
                
                    <Button
                        android:id="@+id/button2"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/numberPicker1"
                        android:layout_marginLeft="20dp"
                        android:layout_marginTop="98dp"
                        android:layout_toRightOf="@+id/numberPicker1"
                        android:text="Cancel" />
                
                    <Button
                        android:id="@+id/button1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignBaseline="@+id/button2"
                        android:layout_alignBottom="@+id/button2"
                        android:layout_marginRight="16dp"
                        android:layout_toLeftOf="@+id/numberPicker1"
                        android:text="Set" />
                
                </RelativeLayout>
                

                快照

                这篇关于如何在对话框中使用数字选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:当我单击搜索按钮时,防止 ProgressDialog 被关闭 下一篇:Android:如何创建一个透明的以对话框为主题的活动

                相关文章

                最新文章

                <legend id='6KJGG'><style id='6KJGG'><dir id='6KJGG'><q id='6KJGG'></q></dir></style></legend>

                <small id='6KJGG'></small><noframes id='6KJGG'>

                  • <bdo id='6KJGG'></bdo><ul id='6KJGG'></ul>
                  <i id='6KJGG'><tr id='6KJGG'><dt id='6KJGG'><q id='6KJGG'><span id='6KJGG'><b id='6KJGG'><form id='6KJGG'><ins id='6KJGG'></ins><ul id='6KJGG'></ul><sub id='6KJGG'></sub></form><legend id='6KJGG'></legend><bdo id='6KJGG'><pre id='6KJGG'><center id='6KJGG'></center></pre></bdo></b><th id='6KJGG'></th></span></q></dt></tr></i><div id='6KJGG'><tfoot id='6KJGG'></tfoot><dl id='6KJGG'><fieldset id='6KJGG'></fieldset></dl></div>

                    <tfoot id='6KJGG'></tfoot>