Kardo Kamal Kardo Kamal - 8 days ago 4x
Java Question

Trying to setup a NumberPicker to show value in Toast

I'm using the NumberPicker tool in Android and I changed the value of the integer to String to be able to show it in the Toast I used

method but I don't think the problem is that.

The thing is when I tap my button no matter what value I pick in the NumberPicker it shows (0). I'm using the
as shown below.

How do I make it get the value that I set on NumberPicker?

numPickerMin = (NumberPicker) findViewById(R.id.numberPickerMinute);


int getvalueminute = numPickerMin.getValue();
final String getValMin= Integer.toString(getvalueminute);

new Button.OnClickListener(){
public void onClick(View v){


You are getting Picker's value after you initialize it so it will always be 0. As I understand your code you want to show correct value in Toast after pressing button? You should move those lines inside OnClickListener:

int getvalueminute = numPickerMin.getValue(); String getValMin= Integer.toString(getvalueminute);