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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:52:45+00:00 2026-06-05T22:52:45+00:00

well the calculation in my app goes like this.. have a edittext box where

  • 0

well the calculation in my app goes like this..

have a edittext box where the input(number) from the user is parsed to int as nos.

based on the input two other sets of edittext box appears.

if nos is 3 the 3 edittext from arrayOfEditText and 3 edittext from arrayOfEditText1 appears..
and the value entered in those sets of edittext are used for calculation.

the incomplete java code is below..

    calculate.setOnClickListener(new View.OnClickListener() {
                            @Override public void onClick(View v) {
                    // TODO Auto-generated method stub
                    chk();          
}       
});     
}   
public void chk()   {   
            EditText[] arrayOfEditText = new EditText[11];
            arrayOfEditText[1] = ((EditText)findViewById(R.id.EditText01));
            arrayOfEditText[2] = ((EditText)findViewById(R.id.EditText02));
            arrayOfEditText[3] = ((EditText)findViewById(R.id.EditText03));
            arrayOfEditText[4] = ((EditText)findViewById(R.id.EditText04));
            arrayOfEditText[5] = ((EditText)findViewById(R.id.EditText05));
            arrayOfEditText[6] = ((EditText)findViewById(R.id.EditText06));
            arrayOfEditText[7] = ((EditText)findViewById(R.id.EditText07));
            arrayOfEditText[8] = ((EditText)findViewById(R.id.EditText08));
            arrayOfEditText[9] = ((EditText)findViewById(R.id.EditText09));
            arrayOfEditText[10] = ((EditText)findViewById(R.id.EditText10));

            EditText[] arrayOfEditText1 = new EditText[11];
            arrayOfEditText1[1] = ((EditText)findViewById(R.id.EditText11));
            arrayOfEditText1[2] = ((EditText)findViewById(R.id.EditText12));
            arrayOfEditText1[3] = ((EditText)findViewById(R.id.EditText13));
            arrayOfEditText1[4] = ((EditText)findViewById(R.id.EditText14));
            arrayOfEditText1[5] = ((EditText)findViewById(R.id.EditText15));
            arrayOfEditText1[6] = ((EditText)findViewById(R.id.EditText16));
            arrayOfEditText1[7] = ((EditText)findViewById(R.id.EditText17));
            arrayOfEditText1[8] = ((EditText)findViewById(R.id.EditText18));
            arrayOfEditText1[9] = ((EditText)findViewById(R.id.EditText19));
            arrayOfEditText1[10] = ((EditText)findViewById(R.id.EditText20));

            for(int i=1;i<=nos;i++)
            {
                if(arrayOfEditText[i].getText().toString().equals("")||arrayOfEditText1[i].getText().toString().equals(""))
                {
                    Toast.makeText(getApplicationContext(), "Dont leave points empty", 0).show();
                }
                else
                {
                    calcul();
                }
            }   }   public void calcul()    {       EditText[] arrayOfEditText = new EditText[11];
            arrayOfEditText[1] = ((EditText)findViewById(R.id.EditText01));
            arrayOfEditText[2] = ((EditText)findViewById(R.id.EditText02));
            arrayOfEditText[3] = ((EditText)findViewById(R.id.EditText03));
            arrayOfEditText[4] = ((EditText)findViewById(R.id.EditText04));
            arrayOfEditText[5] = ((EditText)findViewById(R.id.EditText05));
            arrayOfEditText[6] = ((EditText)findViewById(R.id.EditText06));
            arrayOfEditText[7] = ((EditText)findViewById(R.id.EditText07));
            arrayOfEditText[8] = ((EditText)findViewById(R.id.EditText08));
            arrayOfEditText[9] = ((EditText)findViewById(R.id.EditText09));
            arrayOfEditText[10] = ((EditText)findViewById(R.id.EditText10));

            EditText[] arrayOfEditText1 = new EditText[11];
            arrayOfEditText1[1] = ((EditText)findViewById(R.id.EditText11));
            arrayOfEditText1[2] = ((EditText)findViewById(R.id.EditText12));
            arrayOfEditText1[3] = ((EditText)findViewById(R.id.EditText13));
            arrayOfEditText1[4] = ((EditText)findViewById(R.id.EditText14));
            arrayOfEditText1[5] = ((EditText)findViewById(R.id.EditText15));
            arrayOfEditText1[6] = ((EditText)findViewById(R.id.EditText16));
            arrayOfEditText1[7] = ((EditText)findViewById(R.id.EditText17));
            arrayOfEditText1[8] = ((EditText)findViewById(R.id.EditText18));
            arrayOfEditText1[9] = ((EditText)findViewById(R.id.EditText19));
            arrayOfEditText1[10] = ((EditText)findViewById(R.id.EditText20));
                for(i=1;i<=nos;i++)
                {
                  //perform calculation
                }   }

now the logic to be performed in the //perform calculation area is..

arrayofedittext[1]*arrayofedittext1[1] + arrayofedittext[2]*arrayofedittext1[2] + arrayofedittext[3]*arrayofedittext1[3] + etc based on nos / arrayofedittext[1] + arrayofedittext[2] + arrayofedittext[3] + etc based on nos

so can someone help me complete this coding?? 🙂

  • 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-05T22:52:47+00:00Added an answer on June 5, 2026 at 10:52 pm

    The less times you perform the same action the faster your app will run. So make EditText[] arrayOfEditText and EditText[] arrayOfEditText1 class-scoped variables, define them once in onCreate() and you won’t have to use findViewById() on R.id.EditText** after that point.

    Here’s a function that checks if any of the rows in the calculation are empty, if not you then total will have what you want.

    public void calculateTotal() {
        String first;
        String second;
    
        double firstNum;
        double numerator = 0;
        double denominator = 0;
    
        // This loops counts from nos down to 1. It checks for empty strings and 
        //   sums up the numerator and denominator along the way.
        for(int index = nos; index > 0; index--) {
            first = arrayOfEditText[index].getText().toString();
            second = arrayOfEditText1[index].getText().toString();
    
            if(first.isEmpty() || second.isEmpty()) {
                Toast.makeText(getApplicationContext(), "Dont leave any points empty (" + (index + 1) + ")", Toast.LENGTH_LONG).show();
                return; // Invalid input, warn user and bail out of function!
            }
    
            firstNum = Double.parseDouble(first);
            numerator += firstNum * Double.parseDouble(second);
            denominator += firstNum;
        }
    
        // Do something with total
        double total = numerator / denominator;
    }
    

    Finer Points

    Define arrayOfEditText and arrayOfEditText1 to be visible for the entire class like this:

    public class Example extends Activity {
        EditText[] arrayOfEditText = new EditText[11];
        EditText[] arrayOfEditText1 = new EditText[11];
        ...
    
            @Override
            public void onCreate(Bundle savedInstanceState) 
            {
                ...  
                arrayOfEditText[1] = (EditText) findViewById(R.id.EditText01);
                etc, etc...
    

    You should know that an array is a zero-index list. So the first entries in your arrays (arrayOfEditText and arrayOfEditText1) are null, if you ever try and reference arrayOfEditText[0] expecting an EditText your app will crash.

    Lastly this code assumes that every EditText is a valid Double, if you don’t restrict non-numeric entries already adding a check is quite simple.

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

Sidebar

Related Questions

so I am building a car loan app which requires input from the user,
Say I want to have a simple web app that takes some user input,
Well, I have a class Customer (no base class). I need to cast from
Well, how to create picture link like this up or down votes (on the
I have an ASP.NET MVC 3 (.NET 4) web application. This app fetches data
a noob question here. I have an app that does number calculations. I support
I have an app that allows the user to scale in for a closer
When this callback is made in my app, I have quite a bit work
Well i have a gridview where i have defined the columns on my own
Well i have a transparent div or the background is set to transparent :)

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.