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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:18:56+00:00 2026-06-16T04:18:56+00:00

i am trying to add the add text changed listener into my code so

  • 0

i am trying to add the add text changed listener into my code so when
i edit the text it is automaticly converting the currency to the SELECTED RADIO BUTTON (dollar,euro) without the need to push one of the radio buttons to make it show the answer in the textview.

i have no idea how to do this
i am new to programming searched in google didnt find the answer

package com.gardana.superh;

public class ConvertActivity extends Activity {
TextView mResult;
EditText mToConvert;
RadioGroup mRadioGroup;
RadioButton mDollar, Meuro;





protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_convert);

    mResult = (TextView) findViewById(R.id.result);
    mToConvert = (EditText) findViewById(R.id.toConvert);
    mRadioGroup = (RadioGroup) findViewById(R.id.radioG);
    mDollar = (RadioButton) findViewById(R.id.dollar);
    Meuro = (RadioButton) findViewById(R.id.euro);


    mRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
    {
        public void onCheckedChanged(RadioGroup mradRadioGroup, int checkedId)
        {

            switch (checkedId)
            {

            case R.id.dollar:
            Double dollarConvert = Double.valueOf(mToConvert.getText().toString()); //convert the string to int
            double price = dollarConvert * 3.76;
            mDollar.setChecked(true);
            Meuro.setChecked(false);
            mResult.setText("$"+price);

            break;

            case R.id.euro:

                Double euroConvert = Double.valueOf(mToConvert.getText().toString()); //convert the string to int
                double value = euroConvert * 5;
                mDollar.setChecked(false);
                Meuro.setChecked(true);

                mResult.setText("€" + value);
                Meuro.setChecked(false);

                break;

                default:;
            }
        }
    });



}

}

  • 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-16T04:18:57+00:00Added an answer on June 16, 2026 at 4:18 am

    I would suggest you break down your code to make it easier to do. First you need to add your two listeners so the conversions are preformed when needed.

    mToConvert.addTextChangedListener(new TextWatcher() {
    
        @Override
        public void afterTextChanged(Editable s) {
            convertCurrentAmount();
        }
    
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {                
        }
    
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {                
        }
    
    
    });
    mRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        public void onCheckedChanged(RadioGroup mradRadioGroup, int checkedId)
        {
            convertCurrentAmount();
        }
    });
    

    Because you’re basically going to do the same work in two places, I suggest you create a method which performs the calculation for you. This then can be called whenever you liked to update the conversion.

       public void convertCurrentAmount() {
            int exchangeRate = -1;
            String exchangeSymbol;
            switch (mRadioGroup.getCheckedRadioButtonId()) {
                case R.id.dollar:
                    exchangeRate = 3.76;
                    exchangeSymbol = "$";
                    break;
    
                case R.id.euro:
                    exchangeRate = 5;
                    exchangeSymbol = "€";
                    break;
            }
    
            if (exchangeRate > 0 && exchangeSymbol != null) {
                // Perform Calculation
            }
        }
    

    I’ve also included a suggestion above about how to rework your switch/case to use less code duplication, because theres no point writing the same thing twice.

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

Sidebar

Related Questions

I am trying to add text into a hidden text box in the div
I'm trying to add text to textarea in current pointer position, here's the code
I'm trying yo add text to the editor using some buttons, So actualy I've
I'm trying to add text input's element to my array when user pressed enter
I 'm trying to add text on a specific image. Its working perfectly but
Im trying to add the text contained inside an <li> element when the user
I am trying to add full text search capabilities to my RoR app, but
I'm trying to add a plain text node in a zend form - the
I'm trying to add an additional text field to magento's product review. It looks
I'm trying add data triggers to the default combobox style so each text item

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.