Android: Pass an integer from NumberPicker to another activity
<p>I am using the built in NumberPicker to have the user choose a number. Then the user will hit the "OK" button to confirm and the resulting action will open up another activity. I want the number that the user chooses to be passed through to the other activity when the user hits the "OK" button. I have done buttons that result in opening up a new activity and I know that the NumberPicker has a getValue() and you can pass stuff through with putExtra(), but I am not sure how to combine those with the onClick method. How do I go about doing this?</p>

<pre><code>public class Source1 extends Activity implements View.OnClickListener {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_1);
...(NumberPicker code)
}

@Override
public void onClick(View v) {
    int x = ((NumberPicker) v).getValue();
    Intent intent = new Intent(this, Destination.class);
    intent.putExtra("VarName", x);
    startActivity(intent);
}
}
</code></pre>

<p>This is the xml for my button:</p>

<pre><code>&lt;Button
    android:id="@+id/Id_name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/numberPicker1"
    android:layout_centerHorizontal="true"
    android:onClick="methodName"
    android:text="@string/Ok" /&gt;
</code></pre>

<p>That was my attempt. Is this right/what needs to change? Do I even need the onClick in the button code since I am using the onClick method in the class?</p>
