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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:51:06+00:00 2026-06-17T13:51:06+00:00

What seem to be the problem… My program cannot enter the switch statements. I

  • 0

What seem to be the problem… My program cannot enter the switch statements. I assigned the position to unita and when i use it in the switch statement, it doesn’t respond. But when i tried putting a code outside of the switch statement the program responds normally.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

   ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_spinner_item, list);
   category = (Spinner) findViewById(R.id.categoryList);
   category.setAdapter(adapter);
   category.setOnItemSelectedListener(this);

}

@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
        long arg3) 
{
    // TODO Auto-generated method stub
    int position = category.getSelectedItemPosition();

    switch(position)
    {
        case 0:
        {
            //Length                                
            Length();
        }   
            break;
        case 1:
        {
            //Weight
            Weight();
        }   
            break;
        case 2:
            //Time
            Time();
            break;
        case 3:
            //IT
            IT();
            break;
        case 4:
            //Area
            Area();
            break;
        case 5:
            //Volume
            Volume();
            break;
        case 6:
            //Perimeter
            Perimeter();
            break;
    }               

}
public void Length()
{
    ArrayAdapter<String> lengthadapt = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_spinner_item, length);
    ArrayAdapter<String> lengthadapt2 = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_spinner_item, length);

    unit1 = (Spinner) findViewById(R.id.unit1);
    int unita = unit1.getSelectedItemPosition();   
    unit1.setAdapter(lengthadapt);
    unit1.setSelection(unita);
    unit2 = (Spinner) findViewById(R.id.unit2);
    int unitb = unit2.getSelectedItemPosition();
    unit2.setAdapter(lengthadapt2);
    unit2.setSelection(unitb); 
    b1=(ImageButton) findViewById(R.id.convert1);       

    int con=unita;

switch(con)
{
case 0:         
{   b1=(ImageButton) findViewById(R.id.convert1);   
    b1.setOnClickListener(new OnClickListener() {  
      public void onClick(View v) {           
          t1=(EditText) findViewById(R.id.input1);
          t2=(EditText) findViewById(R.id.input2);  
          Double res;
            String txt;
            int num1=Integer.parseInt(t1.getText().toString());
            res=(double)num1*1000;
            System.out.println(res);
            t2.setText(res.toString());
      }});  
    break;
}
case 1:
    {b1=(ImageButton) findViewById(R.id.convert1);  
        b1.setOnClickListener(new OnClickListener() {  
              public void onClick(View v) {           
                  t1=(EditText) findViewById(R.id.input1);
                  t2=(EditText) findViewById(R.id.input2);  
                  Double res;
                    String txt;
                    int num1=Integer.parseInt(t1.getText().toString());
                    res=(double)num1*1000;
                    System.out.println(res);
                    txt=res.toString();
                    t2.setText(txt);

                  }});  
        break;
    }
case 2:{
    b1=(ImageButton) findViewById(R.id.convert1);   
    b1.setOnClickListener(new OnClickListener() {  
          public void onClick(View v) {           
              t1=(EditText) findViewById(R.id.input1);
              t2=(EditText) findViewById(R.id.input2);  
              Double res;
                String txt;
                int num1=Integer.parseInt(t1.getText().toString());
                res=(double)num1*.01;
                System.out.println(res);
                txt=res.toString();
                t2.setText(txt);

              }});  
    break;
}
case 3:
{
    b1=(ImageButton) findViewById(R.id.convert1);   
    b1.setOnClickListener(new OnClickListener() {  
          public void onClick(View v) {           
              t1=(EditText) findViewById(R.id.input1);
              t2=(EditText) findViewById(R.id.input2);  
              Double res;
                String txt;
                int num1=Integer.parseInt(t1.getText().toString());
                res=(double)num1*.001;
                System.out.println(res);
                txt=res.toString();
                t2.setText(txt);

              }});  
    break;
}
case 4:{
    b1=(ImageButton) findViewById(R.id.convert1);   
    b1.setOnClickListener(new OnClickListener() {  
          public void onClick(View v) {           
              t1=(EditText) findViewById(R.id.input1);
              t2=(EditText) findViewById(R.id.input2);  
              Double res;
                String txt;
                int num1=Integer.parseInt(t1.getText().toString());
                res=(double)num1*.4;
                System.out.println(res);
                txt=res.toString();
                t2.setText(txt);

              }});  
    break;
}
case 5:
{
    b1=(ImageButton) findViewById(R.id.convert1);   
    b1.setOnClickListener(new OnClickListener() {  
          public void onClick(View v) {           
              t1=(EditText) findViewById(R.id.input1);
              t2=(EditText) findViewById(R.id.input2);  
              Double res;
                String txt;
                int num1=Integer.parseInt(t1.getText().toString());
                res=(double)num1*12;
                System.out.println(res);
                txt=res.toString();
                t2.setText(txt);

              }});  
    break;
}
}


switch(unitb)
        {
        case 0:

            break;
        case 1:

            break;
        case 2:

            break;
        case 3:

            break;
        case 4:

            break;
        case 5:

            break;

        }
}
  • 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-17T13:51:07+00:00Added an answer on June 17, 2026 at 1:51 pm

    Declare your unita value globally to use it in other methods.

    int unita;
    
    unit1.setOnItemSelectedListener(new OnItemSelectedListener()
    {
    @Override
    public void onItemSelected(AdapterView<?> arg0, View arg1,
    int arg2, long arg3)
    {
    unita = arg0.getSelectedItemPosition();
    Toast.makeText(getBaseContext(),
    "You have selected item position : " + unita,
    Toast.LENGTH_SHORT).show();
    }
    @Override
    public void onNothingSelected(AdapterView<?> arg0) {}
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It seem I have problem with a twig if statement. {%if fields | length
This problem may seem like school work, but it isn't. At best it is
I seem to have a problem passing some strings on from one form to
I seem to have a problem with getting MVC to fill in my custom
I seem to have a problem understanding how to conditionally test a boolean value
My problem is that I can only seem to click the button once, if
I seem to stumble on problem after problem giving my entities behaviour. I have
I seem to be having a problem removing the image in UIScrollView. I was
I seem to be having a problem checking if a string exists in my
I seem to be running into a problem with temp table garbage collection: CREATE

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.