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

  • Home
  • SEARCH
  • 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 615575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:14:06+00:00 2026-05-13T18:14:06+00:00

Need some advice from you experts out there. I’ve just started with Android programming

  • 0

Need some advice from you experts out there. I’ve just started with Android
programming and while I finally got what I want my “Hello World” to do, I feel
as if I’m bludgening my way through rather than grasping concepts.

I created three EditText boxes. Below those I created three Spinners. Pick a
number in the Spinner and it will show up in the corresponding EditText box.
Spinner 1 correlates to EditText 1, Spinner 2 to EditText 2 and Spinner 3 to
EditText 3. I had a hell of a time getting this to work. I do have some
cleaning up to do.

In my startup class I:

    EditText [] pick_nums = new EditText[3];
    pick_nums[0] = (EditText) findViewById(R.id.r1c1);
    pick_nums[1] = (EditText) findViewById(R.id.r1c2);
    pick_nums[2] = (EditText) findViewById(R.id.r1c3);

    Spinner test1 = (Spinner) findViewById(R.id.spin_pick_num1);
    Spinner test2 = (Spinner) findViewById(R.id.spin_pick_num2);
    Spinner test3 = (Spinner) findViewById(R.id.spin_pick_num3);

//I created a class to initialize the spinners.

Context g = getApplicationContext();
    Initialize_stuff spin1 = new Initialize_stuff(test1, g);
    Initialize_stuff spin2 = new Initialize_stuff(test2, g);
    Initialize_stuff spin3 = new Initialize_stuff(test3, g);

//I created a class to put the number in the corresponding EditText box.
I wanted to avoid having the user press a button to do the populating
and once three numbers are in I’ll do something with them without having to
press a button.

Handle_Picks hp = new Handle_Picks(g, pick_nums);

//Here’s where I think it get kludgy and awkward. To make Handle_Picks work
correctly I created a method to set the context, an array of EditTexts, and
the reference to the class Handle_Picks hp.

Spinner_Listener listen = new Spinner_Listener();    
listen.set_context(g, pick_nums, hp);
test1.setOnItemSelectedListener(listen);
test2.setOnItemSelectedListener(listen);
test3.setOnItemSelectedListener(listen);

//In the Spinner_Listener class

public class Spinner_Listener implements OnItemSelectedListener

static Handle_Picks hp1;  //set in a method
private String num;
String v;
String spin_id;
int vv;

public void onItemSelected(AdapterView<?> parent, View view, int pos,
        long id)
{
    //To make this work I had to find the name of the spinner that was
    //used so I could correlate it with the right EditText

     vv = parent.getId();
     v = parent.getResources().getResourceName(vv);
     spin_id = parent.getResources().getResourceEntryName(vv);
     setNum(parent.getItemAtPosition(pos).toString());
}

public void setNum(String s)
{
    num = s;
    hp1.handle_nums(spin_id, num);
}

//finally in class Handle_Picks I:

public class Handle_Picks extends Activity
{
  static Context theContext;
  EditText [] et;
  String spin_num;

// constructor  
Handle_Picks(Context f, EditText[] array)
{
    theContext = f;
    et = array;
}


public void handle_nums(String id, String aNumber)
{
    spin_num = id;
    if (spin_num.equalsIgnoreCase("spin_pick_num1"))
        et[0].setText(aNumber);
    else if (spin_num.equalsIgnoreCase("spin_pick_num2"))
        et[1].setText(aNumber);
    else if (spin_num.equalsIgnoreCase("spin_pick_num3"))
        et[2].setText(aNumber);
}

Is there a better way to pass or reference resources around various classes?
Having to pass the Context and and array of EditText to class Handle_Picks
before I could use Handle_Picks from class Spinner_Listener doesn’t seem right.
Seems kind of dangerous.

What’s the better way?

  • 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-13T18:14:06+00:00Added an answer on May 13, 2026 at 6:14 pm

    Ummmm…well…very little of what you have here do I like much. Tackling the easy stuff:

    • To get the value of a Spinner, call getSelectedItem(). There is no sense in your messing around with the resources to populate your EditText based off of the Spinner value. In your Spinner_Listener‘s onItemSelected() method, your Spinner is known as parent (Spinner inherits from AdapterView, and getSelectedItem() is a method on AdapterView).

    • Don’t call getApplicationContext(), particularly for UI-related stuff. Your Activity is a Context — just use it.

    • Never implement a constructor on an Activity (e.g., Handle_Picks).

    • Never create an instance of an Activity directly (e.g., new Handle_Picks()).

    Given all the above, you should not need Handle_Picks at all.

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

Sidebar

Related Questions

I need some help from the shell-script gurus out there. I have a .txt
I need some advice as to how I easily can separate test runs for
I need some expect advice on how to handle the following:- I have a
I need some basic CMS functionality with rich text editing. On stack overflow there
I need some info on how to use margins and how exactly padding works.
I need some software to explore and modify some SQLite databases. Does anything similar
We need some input on what is a good design pattern on using AJAX
I need some sort of interactive chart control for my .NET-based web app. I
I need some information about localization. I am using .net 2.0 with C# 2.0
I need some pointers on how to detect unknown hardware using .NET and C++/C#.

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.