2016-08-05 65 views
1

我使用alert 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(); 


    } 

回答

1

,你可以這樣做:

mNumberPicker.setValue(number); 
+0

@rosy你必須創建數選擇器的對象看。 –

+0

這是什麼數字? – rosy

+0

你想要設置的舊號碼 –