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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:01:16+00:00 2026-05-27T14:01:16+00:00

if I have set text in textview in such way, which is not problem:

  • 0

if I have set text in textview in such way, which is not problem:

  tv.setText("" + ANS[i]);

this simply getting from this way.

     String a = tv.getText().toString();
     int A = Integer.parseInt(a);

But in case of setting value in textView.

 tv1.setText("  " + X[i] + "\n" + "+" + " " + Y[i]);

which is like this

              5
             +9

I have problem , this value how to get.

  • 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-27T14:01:17+00:00Added an answer on May 27, 2026 at 2:01 pm

    I haven’t tested this – but it should give you a general idea of the direction you need to take.

    For this to work, I’m going to assume a few things about the text of the TextView:

    1. The TextView consists of lines delimited with "\n".
    2. The first line will not include an operator (+, -, * or /).
    3. After the first line there can be a variable number of lines in the TextView which will all include one operator and one number.
    4. An operator will allways be the first Char of a line.

    First we get the text:

    String input = tv1.getText().toString();
    

    Then we split it up for each line:

    String[] lines = input.split( "\n" );
    

    Now we need to calculate the total value:

    int total = Integer.parseInt( lines[0].trim() ); //We know this is a number.
    
    for( int i = 1; i < lines.length(); i++ ) {
       total = calculate( lines[i].trim(), total );
    }
    

    The method calculate should look like this, assuming that we know the first Char of a line is the operator:

    private int calculate( String input, int total ) {
       switch( input.charAt( 0 ) )
          case '+':
             return total + Integer.parseInt( input.substring( 1, input.length() );
          case '-':
             return total - Integer.parseInt( input.substring( 1, input.length() );             
          case '*':
             return total * Integer.parseInt( input.substring( 1, input.length() );             
          case '/':
             return total / Integer.parseInt( input.substring( 1, input.length() );
    }
    

    EDIT

    So the above as stated in the comment below does “left-to-right” calculation, ignoring the normal order ( + and / before + and -).

    The following does the calculation the right way:

    String input = tv1.getText().toString();
    input = input.replace( "\n", "" );
    input = input.replace( " ", "" );
    int total = getValue( input );
    

    The method getValue is a recursive method and it should look like this:

    private int getValue( String line ) {
      int value = 0;
    
      if( line.contains( "+" ) ) {
        String[] lines = line.split( "\\+" );
        value += getValue( lines[0] );
    
        for( int i = 1; i < lines.length; i++ )
          value += getValue( lines[i] );
    
        return value;
      }
    
      if( line.contains( "-" ) ) {
        String[] lines = line.split( "\\-" );
        value += getValue( lines[0] );
    
        for( int i = 1; i < lines.length; i++ )
          value -= getValue( lines[i] );
    
        return value;
      }
    
      if( line.contains( "*" ) ) {
        String[] lines = line.split( "\\*" );
        value += getValue( lines[0] );
    
        for( int i = 1; i < lines.length; i++ )
          value *= getValue( lines[i] );
    
        return value;
      }
    
      if( line.contains( "/" ) ) {
        String[] lines = line.split( "\\/" );
        value += getValue( lines[0] );
    
        for( int i = 1; i < lines.length; i++ )
          value /= getValue( lines[i] );
    
        return value;
      }
    
      return Integer.parseInt( line );
    }
    

    Special cases that the recursive method does not handle:

    • If the first number is negative e.g. -3+5*8.
    • Double operators e.g. 3*-6 or 5/-4.

    Also the fact the we’re using Integers might give some “odd” results in some cases as e.g. 5/3 = 1.

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

Sidebar

Related Questions

I have set up the full-text search functionality in SQL Server 2008 express. This
I have a XIB set up like in this screenshot: alt text http://emberapp.com/jxpx777/images/interface-builder/sizes/m.png File's
I have a TextView in my layout which has an attribute clickable=true set in
How to set underline text on textview ? I have used following code but
I have a set of data that contains garbled text fields because of encoding
Here's the situation: I have a label's text set, immediately followed by a response.redirect()
let's say I have this set of HTML-markup and CSS #CSS .inputhelp_text { background:
I have a series of buttons that display filenames. If I set the Text
I have a script set up to send out multipart emails; plain text and
In my hello world application, i have a button and a text field set

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.