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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:14:08+00:00 2026-06-14T13:14:08+00:00

Hey everyone, I am in need of some help with my first android app,

  • 0

enter image description here

Hey everyone, I am in need of some help with my first android app, and I have a little experience in programming. So first I wanted to do was something like “Let the user choose whichever method they want to convert from and to, and let them input the value in the TextView then follow by pressing the convert button to finish it with a toast.”

Currently I am having trouble with onClickListener() button to finish of with a toast output, I can’t get the result from the String in switch/case. Also I am not sure that if my code is okay, as I cannot test it :(. I Spent hours trying to get it work but no luck. Need someone to point me to the right direction and what I need to look at, please.

    class convert_handler_CMtoM implements Button.OnClickListener {

    public void onClick(View v) {

        if (v == btnDisplay) {

            if (MMtoCM.isChecked())
            {
                int Amount = (int) Float.parseFloat(et1.getText().toString());
                int formula = (int) (Amount * 10) ; 
                String result = String.valueOf(formula);
            }

            if (CMtoMM.isChecked())
            {
                double Amount = (double)Float.parseFloat(et1.getText().toString());
                double formula = (double) (Amount / 10) ; 
                String result = String.valueOf(formula);
            }
        }

    }   

    private OnClickListener btnDisplay = new OnClickListener() {
        public void onClick(View v) {
            // Perform action on clicks
            RadioButton rb = (RadioButton) v;
            Toast.makeText(second.this, rb.getText(), result, Toast.LENGTH_SHORT).show();
        }
    };
}
  • 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-14T13:14:09+00:00Added an answer on June 14, 2026 at 1:14 pm
    package com.example.radiobuttongroup;
    
    import android.app.Activity;
    import android.app.AlertDialog;
    import android.content.DialogInterface;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.LinearLayout;
    import android.widget.RadioButton;
    import android.widget.Toast;
    
    import com.example.radiobuttongroup.R.id;
    
    public class MainActivity extends Activity {
    
        RadioButton rd1, rd2, rd3;
        Button btn1;
        int type;
        String title;
        EditText input;
        AlertDialog.Builder editalert;
        AlertDialog alertd;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            rd1 = (RadioButton) findViewById(id.radioButton1);
            rd2 = (RadioButton) findViewById(id.radioButton2);
            rd3 = (RadioButton) findViewById(id.radioButton3);
            btn1 = (Button) findViewById(id.button1);
    
    
    
            rd1.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    rd2.setChecked(false);
                    rd3.setChecked(false);
                    type = 1;
                    title = "cm to m";
                }
            });
    
            rd2.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    rd1.setChecked(false);
                    rd3.setChecked(false);
                    type = 2;
                    title = "m to cm";
    
                }
            });
    
            rd3.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    rd2.setChecked(false);
                    rd1.setChecked(false);
                    type = 3;
                    title = "mm to cm";
                }
            });
    
            btn1.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    calculate(title, type);
    
                }
            });
        }
    
        void calculate(String title, final int type) {
            try {
    
                editalert = new AlertDialog.Builder(MainActivity.this);
                alertd = editalert.create();
                editalert.setTitle("Calculator");
                editalert.setMessage(title);
                input = new EditText(MainActivity.this);
                LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                        LinearLayout.LayoutParams.FILL_PARENT,
                        LinearLayout.LayoutParams.FILL_PARENT);
                input.setLayoutParams(lp);
                input.setText("1000");
                editalert.setView(input);
    
                editalert.setPositiveButton("Convert",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int whichButton) {
                                int value = Integer.valueOf(input.getText().toString());
    
                                switch (type) {
                                case 1:
                                    Toast.makeText(
                                            MainActivity.this,
                                            String.valueOf(value / 100),
                                            Toast.LENGTH_LONG).show();
                                    dialog.cancel();
                                    alertd.dismiss();
                                    break;
    
                                case 2:
                                    Toast.makeText(MainActivity.this,
                                            String.valueOf(value * 100),
                                            Toast.LENGTH_LONG).show();
                                    dialog.cancel();
                                    alertd.dismiss();
                                    break;
    
                                case 3:
                                    Toast.makeText(MainActivity.this,
                                            String.valueOf(value / 100),
                                            Toast.LENGTH_LONG).show();
                                    dialog.cancel();
                                    alertd.dismiss();
                                    break;
                                default:
                                    break;
                                }
    
                            }
                        });
                editalert.show();
            } catch (Exception e) {
                Log.v("hata", e.toString());
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey everyone, great community you got here. I'm an Electrical Engineer doing some programming
Hey everyone I am a newbie and would love some help. I got the
Hey everyone, I have a database result that returns from a method. I need
Hey everyone. Hopefully I can explain this correctly. I have some URL's which I
Hey everyone. I have a fair amount of experience developing iOS apps, but nothing
Hey everyone, Again I need your help :D Is it possible to add the
Hey everyone I am making my first applet for java today. I have been
Hey everyone I am having a little problem with my jQuery I am trying
Hey everyone, I'm back and looking forward to more of your brilliance. I have
Hey everyone, here is the site in question: http://www.myvintagesecret.com/ I have a bunch of

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.