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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:41:53+00:00 2026-05-22T20:41:53+00:00

I am trying to do something extremely basic! And it wont work :(. I

  • 0

I am trying to do something extremely basic! And it wont work :(. I feel like I’m going in circles.

Here’s the rundown: I would like the user to input a series of numbers into an EditText box (separated by comma’s). After the add button is selected a split method will separate each number into its own slot in a String[]. EVENTUALLY, if I can get this part to work, the numbers will be pulled out of the array and converted to doubles.Then they will be used in a calculation or two. I have tried several different ways of getting this done and it seems like the problem is coming from the split method or for-loop. The code listed below returns an empty string.

Also, through my trial and error I ended up with a return method calculate(). How much stuff can a cram in an onClick method? Was this a bad idea? Please be as a brutal as needed!!! I’m new to android. Thanks in advance.


package com.simplydesign.android.standarddev;

import android.app.Activity;
import android.os.Bundle;
import android.widget.*;
import android.view.*;

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

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    final Button addBtn = (Button) findViewById(R.id.addBtn);
    final EditText userData = (EditText) findViewById(R.id.editText1);
    final TextView dataCollection = (TextView) findViewById(R.id.textView1);

    addBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            String[] rawData;
            rawData = userData.getText().toString().split(",");
            dataCollection.setText(calculate(rawData));
        }

    });

}

public String calculate(String[] a) {

    String output = "";

    for (int i = 0; i < a.length - 1; i++) {
        output += " " + a[i];
        } return output;
}
}
  • 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-22T20:41:54+00:00Added an answer on May 22, 2026 at 8:41 pm

    In your for-loop you should iterate from 0 to a.length - 1. This means the loop must look like:

    for (int i = 0; i < a.length; i++) { /* ... */ }
    

    But you’d better use something like that:

    public String calculate(String[] a) {
    
        StringBuilder output = new StringBuilder();
    
        for (String s : a) {
            output.append(' ').append(s);
        }
        return output.toString();
    }
    

    Unfortunately, I don’t think it will completly solve your problem but it definitely fixes one error.

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

Sidebar

Related Questions

I'm trying something like this Output.py print Hello Input.py greeting = raw_input(Give me the
I'm trying something like this, but this example does not work. jsObj = {};
I've been trying to do something extremely simple, yet I can't make it work!
I feel I am missing something extremely basic; yet I have spent hours to
I am trying something very simple, but for some reason it does not work.
I'm trying something like this: [ServiceContract ( CallbackContract = typeof (CallbackContract_1), CallbackContract = typeof
As the title goes I am trying something like $(ul li:nth-child(' + xx +
Is it possible to set for(AssociatedControlID) attribute using jQuery? I am trying something like
Now Im sure Im doing something extremely schoolboy here, but Im seriously hitting my
This is driving me crazy, I am trying to do something like: $this->data =

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.