Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8922415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:49:38+00:00 2026-06-15T06:49:38+00:00

I am using the built in NumberPicker to have the user choose a number.

  • 0

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?

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);
}
}

This is the xml for my button:

<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" />

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T06:49:41+00:00Added an answer on June 15, 2026 at 6:49 am

    Change your code as to get selected value from NumberPicker on Button click:

    @Override
    public void onClick(View v) {
    
        NumberPicker numPicker = (NumberPicker)findViewById(R.id.NumberPicker_id);
        int x = numPicker.getValue();
        Intent intent = new Intent(this, Destination.class);
        intent.putExtra("VarName", x);
        startActivity(intent);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using built in Drupal 6 user module, fore user registration, forgot-your-password-emails and
How do I do the following using built-in modules only? I have a list
I have an application built using JSF1.2. I have a home page which has
I am using built-in asp.net Role and membership provider in my website. when user
MVC3 vb.net Application using built in session management. I have an mvc3 application that
I have a requirement such that I need to add two integers using built
I have a Custom Post Type, 'ioni_codex' I am using built-in Wordpress category as
I have an ASP.NET app using built-in Membership functionality. As such, I have a
I have inherited an app set up using built using rails using the facebooker
Hello I'm using built in Google Map to show route to user. When I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.