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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:15:36+00:00 2026-05-25T02:15:36+00:00

In an Android app, I’m using two EditText controls and multiplying their two values.

  • 0

In an Android app, I’m using two EditText controls and multiplying their two values.
If one EditText is null and in the second one I put a value, it’s not working properly.
How can I deal with this case, in which I have a value in one EditText and a null in the other and I want to multiply the two values?

  • 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-25T02:15:37+00:00Added an answer on May 25, 2026 at 2:15 am

    First of all, you need to have a trigger for when to perform the calculation. Say it’s a button, or, even better, every time the value of one of your EditTexts changes:

    private EditText editText1,
                     editText2;
    private TextView resultsText;
    
    ...............................
    
    // Obtains references to your components, assumes you have them defined
    // within your Activity's layout file
    editText1 = (EditText)findViewById(R.id.editText1);
    editText2 = (EditText)findViewById(R.id.editText2);
    
    resultsText = (TextView)findViewById(R.id.resultsText);
    
    // Instantiates a TextWatcher, to observe your EditTexts' value changes
    // and trigger the result calculation
    TextWatcher textWatcher = new TextWatcher() {
        public void afterTextChanged(Editable s) {
            calculateResult();
        }
        public void beforeTextChanged(CharSequence s, int start, int count, int after){}
        public void onTextChanged(CharSequence s, int start, int before, int count){}
    };
    
    // Adds the TextWatcher as TextChangedListener to both EditTexts
    editText1.addTextChangedListener(textWatcher);
    editText2.addTextChangedListener(textWatcher);
    
    .....................................
    
    // The function called to calculate and display the result of the multiplication
    private void calculateResult() throws NumberFormatException {
      // Gets the two EditText controls' Editable values
      Editable editableValue1 = editText1.getText(),
               editableValue2 = editText2.getText();
    
      // Initializes the double values and result
      double value1 = 0.0,
             value2 = 0.0,
             result;
    
      // If the Editable values are not null, obtains their double values by parsing
      if (editableValue1 != null)
        value1 = Double.parseDouble(editableValue1.toString());
    
      if (editableValue2 != null)
        value2 = Double.parseDouble(editableValue2.toString());
    
      // Calculates the result
      result = value1 * value2;
    
      // Displays the calculated result
      resultsText.setText(result.toString());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.