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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:08:05+00:00 2026-05-25T13:08:05+00:00

I want to use the users input from the edit text, covert it into

  • 0

I want to use the users input from the edit text, covert it into an int and use it in my switch statment

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.text.Editable;
import android.text.InputType;
import android.view.Display;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ToggleButton;

public class MainScreen extends Activity implements View.OnClickListener {
    Button convert;
    Button erase;
    EditText display;
    ToggleButton switcher;
    int input;



@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);


             pause.start();
    // Calls my variables
    InitializeVars();
}

// SLEEP 2 SECONDS HERE ...
Thread pause = new Thread() {
    public void run() {
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

};

// My variables
private void InitializeVars() {
    // TODO Auto-generated method stub
    convert = (Button) findViewById(R.id.bConvert);
    erase = (Button) findViewById(R.id.bErase);
    display = (EditText) findViewById(R.id.etDisplay);
    display.setInputType(InputType.TYPE_CLASS_NUMBER);
    switcher = (ToggleButton) findViewById(R.id.tbSwitch);

    switcher.setOnClickListener(this);
    convert.setOnClickListener(this);
    erase.setOnClickListener(this);

}

// My functions for anything that is clickable embedded with a switch
// statement
public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()) {
    case R.id.tbSwitch:
        if (switcher.isChecked()) {
            display.setText("Text1");
        } else {
            display.setText("Text2");
        }
        break;
    case R.id.bErase:
        display.getText().clear();
        break;
    case R.id.bConvert:
        input = Integer.getInteger(display.getText().toString());
        input = (input / 10);
        switch (input) {
            case input = 10:
        }
        break;
    default:
        break;
    }
}

}

So after the input this is what it looks like
and when i try to use my input in my case(for the switch statment) get “case expressions must be constant expressions”

  • 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-25T13:08:06+00:00Added an answer on May 25, 2026 at 1:08 pm

    Well, the first thing I’m noticing about that line is that you’re trying to give input, which is an int an Editable. display.getText() returns an Editable object. I think what you actually want is

    input = Integer.parseInt(display.getText().toString());
    

    Since parseInt() will throw a NumberFormatException, you might want to implement a try/catch block to catch any input that isn’t an integer. It will make your application more robust.

    As for your thread. You don’t call it anywhere. It’s fine but wherever you need it, you must call pause.start() though it’s really unnecessary. I agree with President Evil on that regard.

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

Sidebar

Related Questions

I want to use input from a user as a regex pattern for a
Hay guys, i want to use something like this users = User.objects.all() but i
When users go on my website, I want to force them to use Internet
I'm using jQuery to alter things when a user enters text into an input.
So I have an input form that I want to use to update a
I'm building an application where users can add, edit and delete users from the
Hi i want to get changed text value from JQuery but i can't select
I want to use an existing user and user group table that the forums
We want to use the same user-id across all our dev tools, but this
I want to use a case statement in my user-defined functions because I need

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.