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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:38:46+00:00 2026-05-27T08:38:46+00:00

Ok,so Im trying to make a Currency Converter between dollars and euros based on

  • 0

Ok,so I”m trying to make a Currency Converter between dollars and euros based on a tutorial I found on the web.The problem is that the tutorial is relying on 2 radio buttons to switch between the conversion, a reference for order stating to the program which method to call first.I want the program to make that conversion independetly from the two radio buttons and instantaneously,for instance if I write a number in the euro or dollar editText view…then clicking on the convert button will make the appropriate conversion.But I cannot because there are 2 methods and unless a have a way to display their input simultaneously it won’t work.So my question is how ca I update the two editText views simultaneously when I press the convert button?Thank you

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class ConvertorActivity extends Activity {
    TextView dollars;
    TextView euros;

    Button convert;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);

        dollars = (TextView)this.findViewById(R.id.dollars);
        euros = (TextView)this.findViewById(R.id.euros);



        convert = (Button)this.findViewById(R.id.convert);

        convert.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                convertBoth();

            }
        });
    }

    public void convertBoth(){
        convertDollarsToEuros();
        convertEurosToDollars();
    }
    protected void convertDollarsToEuros() {
        double val = Double.parseDouble(dollars.getText().toString());
        // in a real app, we'd get this off the 'net
        euros.setText(Double.toString(val*0.67));
    }

    protected void convertEurosToDollars() {
        double val = Double.parseDouble(euros.getText().toString());
        // in a real app, we'd get this off the 'net
        dollars.setText(Double.toString(val/0.67));
    }
}
  • 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-27T08:38:47+00:00Added an answer on May 27, 2026 at 8:38 am

    I think what you want is this:

    • If the user changed the dollar amount, convert it to euro
    • If the user changed the euro amount, convert it to dollar

    If that’s the case, you can add a member variable mLastEditedViewId and use a TextWatcher to track which field was last changed. Then, onClick, call convertDollarsToEuros() or convertEurosToDollars accordingly.

    In onCreate:

      dollars.addTextChangedListener(new MyTextWatcher(dollars));
      euros.addTextChangedListener(new MyTextWatcher(euros));
    
      convert.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
          switch (mLastEditedViewId) {
          case R.id.dollars:
            convertDollarsToEuros();
            break;
          case R.id.euros:
            convertEurosToDollars();
            break;
          }
        }
      });
    

    Define an inner class for the TextWatcher:

    private class MyTextWatcher implements TextWatcher {
      private int mTextViewId;
      public MyTextWatcher(TextView view) {
        mTextViewId = view.getId();
      }
      public void beforeTextChanged(CharSequence s, int start, int count, int after) {
      }
      public void onTextChanged(CharSequence s, int start, int before, int count) {
        mLastEditedViewId = mTextViewId;
      }
      public void afterTextChanged(Editable s) {
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make use of a currency conversion web service in my
I'm trying make an entity with doctrine that has three associations with other entities
Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
I am trying to make a rest service that receives complex types from a
I am building a django app that requires some currency entries. I am trying
I am trying to make a currency value. >> 100.00 I tried this: irb(main):021:0>
I'm trying to make a select statement that joins results from three in-line table
I'm learning java and I'm trying to make a very simple application that does
Right now I'm trying make some browser based game. But I have little questions.
I'm trying make an WPF application that I could copy/cut and paste files info

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.