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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:27:06+00:00 2026-06-17T07:27:06+00:00

I am trying to recalculate every time the user changes input so I have

  • 0

I am trying to recalculate every time the user changes input so I have used a TextWatcher. It calculates when the application starts when text is changed it does not recalculate when I have entered a new value. Could someone tell me what I am doing wrong? Is using the “onTextChanged” correct and would I have to put the whole calculation in that procedure or just call the variables one and two variable that change? Please ignore the spinner.
Thanks in advance.

public class AndroidActivity extends Activity implements TextWatcher{

  private Spinner spinner1; 

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.pounds);
    addListenerOnSpinnerItemSelection();

    int one = 0;
    int two = 0;



    try{
      EditText one100lbs = (EditText) findViewById(R.id.one100lbs);
      one = Integer.valueOf(one100lbs.getText().toString().trim());
    }
    catch (NumberFormatException e)
    {
      one = -1;
    }

    try{
      EditText tenPounds = (EditText) findViewById(R.id.tenPounds);
      two = Integer.valueOf(tenPounds.getText().toString().trim()); 
    }
    catch (NumberFormatException e)
    {
      two = -1;
    }

    int result = one + two;

    TextView textView = (TextView) findViewById(R.id.editText1);
    textView.setText(String.valueOf(result)); 




}

//create spinner 
public void addListenerOnSpinnerItemSelection() {
    spinner1 = (Spinner) findViewById(R.id.other_spinner);
    spinner1.setOnItemSelectedListener(new CustomOnItemSelectedListener());
  }

@Override
public void afterTextChanged(Editable s) {
    // TODO Auto-generated method stub
}

@Override
public void beforeTextChanged(CharSequence s, int start, int count,
        int after) {    
    // TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
    // TODO Auto-generated method stub

    int one = 0;
    int two = 0;

    try{
      EditText one100lbs = (EditText) findViewById(R.id.one100lbs);
      one = Integer.valueOf(one100lbs.getText().toString().trim());
    }
    catch (NumberFormatException e)
    {
      one = -1;
    }

    try{
      EditText tenPounds = (EditText) findViewById(R.id.tenPounds);
      two = Integer.valueOf(tenPounds.getText().toString().trim()); 
    }
    catch (NumberFormatException e)
    {
      two = -1;
    }

    int result = one + two;

    TextView textView = (TextView) findViewById(R.id.editText1);
    textView.setText(String.valueOf(result)); 
}

}

  • 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-17T07:27:07+00:00Added an answer on June 17, 2026 at 7:27 am

    It seems you are missing binding textview with TextWatcher.

    You need to do something like to bind textview with TextWatcher:

    text = (EditText)findViewById(R.id.yourTextField);
    text.addTextChangedListener(this);
    

    Read this tutorial for simple example.

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

Sidebar

Related Questions

trying to figure out why this is happening - I have an input text
I have a class that is used as part of a financial application. The
I'm trying to use MVVM for the first time. I have a Windows Phone
Possible Duplicate: How to recalculate correct position I have been trying to achive this
Trying to get a wildcard search to pick up on any text in org_name
trying to get same string on tooltip as is in the Text e.g. Text=<%#
I'm trying to recalculate percentages in an after_update callback of my model. def update_percentages
I'm maintaining a Sencha Touch 1.1 application and I'm trying to resolve an issue
I am adding a feature to my program in which the user will have
I am trying to implement a feature and I have no idea how to

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.