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 6809231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:03:41+00:00 2026-05-26T20:03:41+00:00

I think the following is a basic problem. I using this number Picker as

  • 0

I think the following is a basic problem.

I using this number Picker as there is none provided by Android SDK:
http://www.quietlycoding.com/?p=5&cpage=1#comment-10645

I have integrated it in an inflated alertdialog. Here the inflated layout:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
>
    <com.example.NumberPicker
        android:padding="10dp"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
</LinearLayout>

I have added a button to the alertdialog. If it is clicked, I want to get the current value of the number picker.

The number picker class provides a function:

 public static int getCurrent() {
        return mCurrent;
    }

Problem is that I am not aware how to call it. I have no object of the class.
If I call it via com.example.NumberPicker.getCurrent(), I have to declare it static and this has some negative side-effects.

Does someone know how I get the object of the picker class in order to call the getCurrent() function?

I think simple to create a new object is not the right way, because I want to call the function from the running object in my alerdialog.

Edit:
As I have expected:

NumberPicker np = new NumberPicker(MainScreen.this);
Log.v("TEST", "" + np.getCurrent());

This gives me always 0

Edit 2:
I added an Android ID:

<com.example.NumberPicker
        android:id="@+id/numberPicker"
        android:padding="10dp"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

I my code I do following:

    LayoutInflater factory = LayoutInflater.from(this);
            final View textEntryView = factory.inflate(
                    R.layout.backfall_layout, null);



            new AlertDialog.Builder(MainScreen.this)
                    .setTitle(this.getString(R.string.relapse))
                    .setView(textEntryView)
                    .setPositiveButton("OK",
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,
                                        int whichButton) {
                                NumberPicker np = (NumberPicker) findViewById(R.id.numberPicker);

                                Log.v("TEST", "" + np.getCurrent());

--

But now my App crashes after pressing the button..

Edit 3:

Solved it: I have to call

NumberPicker np = (NumberPicker) textEntryView.findViewById(R.id.cigarettesPicker);
            np.setCurrent(1);
  • 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-05-26T20:03:42+00:00Added an answer on May 26, 2026 at 8:03 pm

    Does someone know how I get the object of the picker class in order to call the getCurrent() function?

    1. Add an android:id value to your NumberPicker element in your layout XML.

    2. When you inflate the layout for your AlertDialog, call findViewById() on the inflated layout, passing in the ID you supplied in step #1, and casting the result to be a NumberPicker.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A friend who studies pure mathematics ask me to think about the following problem.
I would like to do the following but I don't think this will work:
I have been having the following problem, i think it's probably due to the
I'm encountering a very strange problem using g++ 4.1.2. I have a very basic
Creating simple app using GAE / Django-nonrel (I don't think the problem is specific
Following the apparent tradition of of using this question as the basis of new
Think about the following: Your ISP offers you a dynamic ip-address (for example 123.123.123.123).
Given I have two File objects I can think of the following implementation: public
The following code is an example of what I think would qualify as pseudocode,
Following is some obviously-defective code for which I think the compiler should emit a

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.