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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:44:49+00:00 2026-05-30T01:44:49+00:00

How can I make it so when I refer to the display1 variable, I

  • 0

How can I make it so when I refer to the display1 variable, I refer to double, and not the string? The program still refers to display1 as a string. I want the double.

[code]
package rechee.cool;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class HelloAndroidActivity extends Activity {
    /** Called when the activity is first created. */

    double counter1=0;
    double counter2=0;



     public EditText display;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        // Associate the button variable with the xml reference



        display= (EditText) findViewById(R.id.editText1);}
             //

             ////

//////////////////////////////

            public void onClick(View v) {
                switch(v.getId()){
                    case R.id.bOne:
                    display.append("1");
                        break;
                    case R.id.bTwo:

                        display.append("2");
                        break;
                    case R.id.bThree:
                        display.append("3");
                        break;
                    case R.id.bFour:
                        display.append("4");
                        break;
                    case R.id.bFive:
                        display.append("5");
                        break;
                    case R.id.bSix:
                        display.append("6");
                        break;

                    case R.id.bSeven:
                        display.append("7");
                        break;
                    case R.id.bEight:
                        display.append("8");
                        break;
                    case R.id.bNine:
                        display.append("9");
                        break;
                    case R.id.bZero:
                        display.append("0");
                        break;
                    case R.id.bPoint:
                        display.append(".");
                        break;
                    case R.id.bClear:
                        display.setText("");
                        break;
                    case R.id.bAdd:
                        // to get string of EditText 
                        String display1= display.getText().toString();
                        Double.parseDouble(display1);
                        //to test if display1 is double
                        counter1+= display1;
[/code]

Help would be much appreciated.

  • 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-30T01:44:50+00:00Added an answer on May 30, 2026 at 1:44 am
            String display1= display.getText().toString();
            try {
                double dDisplay1 = Double.parseDouble(display1);
                //to test if display1 is double
                counter1+= dDisplay1;
    
            } catch (NumberFormatException e) {
    
                //if couldn't parse to double it will throw
                //this (NumberFormatException) exception and you can catch it
                //print something like "text is not double" or do whatever you want.
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I make a ForeignKey refer back to the object itself? I'm trying
I can make Firefox not display the ugly dotted focus outlines on links with
In C# you can make a block inside of a method that is not
so that you can make your program concurrent easily in the future.
What do sender and eventArgs mean/refer to? How can I make use of them
Is it possible to make a table row expand and collapse? Can anyone refer
I can make a DAO recordset in VB6/Access do anything - add data, clean
How can make a link within a facebox window that redirects it to another
I can make a single row IKImageBrowserView by setting the [imageBrowser setContentResizingMask:NSViewWidthSizable]; but in
Can someone tell me how I can make a table be 100% height in

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.