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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:25:25+00:00 2026-06-11T16:25:25+00:00

I’m writing a simple app in Android. I’ve encountered this problem: I’ve two EditText

  • 0

I’m writing a simple app in Android.

I’ve encountered this problem: I’ve two EditText and a Button. The value of one EditText must be a multiple of the other one EditText.

When the user insert a value in the first EditText and then press the button, the other EditText should show the value calculated with the user input.
This should be possible in other verse, too.

Like a simple unit converter. When I insert value1 in EditText1 and press convert the app must show the converted value in EditText2, but if I insert a value2 in EditText2 and press convert button the app must show the converted value in EditText1.
My problem is: how can I recognize in which EditText there are last user-input?

public void convert(View view) {
    EditText textInEuro = (EditText) findViewById(R.id.euroNumber);
    EditText textInDollar = (EditText) findViewById(R.id.dollarNumber);
    if (toDollar) {
        String valueInEuro = textInEuro.getText().toString();
        float numberInEuro = Float.parseFloat(valueInEuro);
        // Here the conversione between the two currents
        float convertedToDollar = unit * numberInEuro;
        // set the relative value in dollars
        textInDollar.setText(Float.toString(convertedToDollar));
    }

    if (toEuro) {
        String valueInDollar = textInDollar.getText().toString();
        float numberInDollar = Float.parseFloat(valueInDollar);
        //Here the conversione between the two currents
        float convertedToEuro = numberInDollar / unit;
        //set the relative value in dollars
        textInEuro.setText(Float.toString(convertedToEuro));
    }
}

This is the code written. I’ve thinked to use OnClickListener..but it isn’t a good idea..

  • 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-11T16:25:26+00:00Added an answer on June 11, 2026 at 4:25 pm

    You can add a TextWatcher to your two EditText in order to know which one has been updated last.

    public class MainActivity extends Activity {
    
    EditText dollar;
    EditText euro;
    
    private static final int EURO = 0;
    private static final int DOLLAR = 1;
    
    private int lastUpdated = DOLLAR;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        dollar = findViewById(R.id.dollar);
        euro = findViewById(R.id.euro);
    
        dollar.addTextChangedListener(new TextWatcher() {
    
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                lastUpdated = DOLLAR;
    
            }
    
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
    
            }
    
            @Override
            public void afterTextChanged(Editable s) {
    
            }
        });
    
        euro.addTextChangedListener(new TextWatcher() {
    
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                lastUpdated = EURO;
    
            }
    
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
    
            }
    
            @Override
            public void afterTextChanged(Editable s) {
    
            }
        });
    
    }
    
    public void convert(View view) {
        switch (lastUpdated) {
        case EURO:
            //Do work for euro to dollar
            break;
        case DOLLAR:
            //Do work for dollar to euro
            break;
        default:
            break;
        }
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am writing an app with both english and french support. The app requests
I'm making a simple page using Google Maps API 3. My first. One marker
I've tracked down a weird MySQL problem to the two different ways I was
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the

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.