2017-05-28 22 views
0

我一直在试图显示从每次运行时举杯消息,但数量选择器的值,我得到android.widget.NumberPicker{/*some vales in here*/}。我怎样才能让数字选择器上的选定号码显示在吐司消息中?显示数字选择器值

public class NewStudy extends AppCompatActivity { 

    final NumberPicker mynp = new NumberPicker(this); 
    mynp.setMaxValue(24); 
    mynp.setMinValue(1);    

    public void onClick(DialogInterface dialogInterface, int i) { 
     Toast.makeText(NewStudy.this,"value: " + mynp,Toast.LENGTH_SHORT).show(); 
    }         
} 

回答

0

尝试:

public void onClick(DialogInterface dialogInterface, int i) { 
    int value = mynp.getValue(); 
    Toast.makeText(NewStudy.this,"value: " + value,Toast.LENGTH_SHORT).show(); 
} 
+0

它终于奏效。我现在可以在我的Toast消息中显示我的号码选择器值。涂料东西的人。 –