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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:22:10+00:00 2026-06-10T12:22:10+00:00

I am new to Android code development…I am developing a Android calculator apps and

  • 0

I am new to Android code development…I am developing a Android calculator apps and does not understand why the two EditTexts (first input and second input) cannot accept decimal places but can only input integers…Here attached as follows are the codes:

Thanks!

=============Main Activity===============================

package com.trial.jm4_calculator;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;
import android.support.v4.app.NavUtils;

public class MainActivity extends Activity {

    private TextView output;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

    Button btn1 = (Button) findViewById(R.id.button1);
    btn1.setOnClickListener(btn1Listener);
    output = (TextView) findViewById(R.id.lblOutput);
    }

View.OnClickListener btn1Listener = new View.OnClickListener() {
    public void onClick(View v) {
       double opd1, opd2;
       double result = 0.0;
       EditText txtOpd1, txtOpd2;
       RadioButton rdbAdd, rdbSubtract, rdbMultiply, rdbDivide;
       CheckBox chkDivide;

       txtOpd1 = (EditText) findViewById(R.id.txtOpd1);
       txtOpd2 = (EditText) findViewById(R.id.txtOpd2);

       opd1 = Double.parseDouble(txtOpd1.getText().toString());
       opd2 = Double.parseDouble(txtOpd2.getText().toString());

       rdbAdd = (RadioButton) findViewById(R.id.rdbAdd);
       if (rdbAdd.isChecked()) {
           result = opd1 + opd2;
       }
       rdbSubtract = (RadioButton) findViewById(R.id.rdbSubtract);
       if (rdbSubtract.isChecked()) {
           result = opd1 - opd2;
       }
       rdbMultiply = (RadioButton) findViewById(R.id.rdbMultiply);
       if (rdbMultiply.isChecked()) {
           result = opd1 * opd2;
       }
       rdbDivide = (RadioButton) findViewById(R.id.rdbDivide);
       if (rdbDivide.isChecked()) {

              result = opd1 / opd2;            
       }
       output.setText("Answer = " + result);
    }
};
}

====================Main.xml===================================

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent" 
    android:orientation="vertical" 
    xmlns:android="http://schemas.android.com/apk/res/android">
    <LinearLayout 
        android:layout_height="wrap_content" 
        android:layout_width="fill_parent" 
        android:orientation="horizontal"> 
        <TextView 
            android:layout_height="wrap_content" 
            android:layout_width="wrap_content" 
            android:text="First Input: "/> 
        <EditText 
            android:layout_height="wrap_content" 
            android:layout_width="fill_parent" 
            android:inputType="number" 
            android:id="@+id/txtOpd1"/> 
    </LinearLayout>
    <RadioGroup 
        android:layout_height="wrap_content" 
        android:layout_width="fill_parent" 
        android:orientation="horizontal" 
        android:id="@+id/rdgOp"> 
        <RadioButton 
            android:layout_height="wrap_content" 
            android:layout_width="wrap_content" 
            android:text="+ " 
            android:id="@+id/rdbAdd"/> 
        <RadioButton 
            android:layout_height="wrap_content" 
            android:layout_width="wrap_content" 
            android:text="- " 
            android:id="@+id/rdbSubtract"/> 
        <RadioButton 
            android:layout_height="wrap_content" 
            android:layout_width="wrap_content" 
            android:text="* " 
            android:id="@+id/rdbMultiply"/> 
        <RadioButton 
            android:layout_height="wrap_content" 
            android:layout_width="wrap_content" 
            android:text="/ " 
            android:id="@+id/rdbDivide"/> 
    </RadioGroup>
    <LinearLayout 
        android:layout_height="wrap_content" 
        android:layout_width="fill_parent" 
        android:orientation="horizontal"> 
        <TextView 
            android:layout_height="wrap_content" 
            android:layout_width="wrap_content" 
            android:text="Second Input: "/> 
            <EditText 
                android:layout_height="wrap_content" 
                android:layout_width="fill_parent" 
                android:inputType="number" 
                android:id="@+id/txtOpd2"/> 
     </LinearLayout> 
     <Button 
         android:layout_height="wrap_content" 
         android:layout_width="wrap_content" 
         android:text="Compute" 
         android:id="@+id/button1"/> 
     <TextView 
         android:layout_height="wrap_content" 
         android:layout_width="wrap_content" 
         android:id="@+id/lblOutput"/> 
</LinearLayout>
  • 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-10T12:22:12+00:00Added an answer on June 10, 2026 at 12:22 pm

    If you want to use Decimal Number only on your EditText

    use the xml attribute android:inputType="numberDecimal" in your EditText widget your EditText declaration will be like this:

    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="numberDecimal" />
    

    If you want to use Signed Decimal Number than combine the two Xml attributes android:inputType="numberDecimal" and android:inputType="numberSigned". Your EditText declaration will be like this:

    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="numberDecimal|numberSigned" >
    
    </EditText>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am totally new to Android development. I'm not looking for code but what
I am new to android development and my code is not working how it
i am new to android development. I am use the following code to set
I am new to Android development and am facing a slight issue. My first
I am new to Android app development and i'm trying to debug my code
I am very new to Android development. I have this code: Button btnLaunch; btnLaunch=(Button)findViewById(R.id.btnLaunch);
I am totally new to android development....what piece of code shall I write to
I'm new to Android development and I'm trying to code a little app which
I'm new to Android development and I'm wondering why my code crashes the Android
I am new to Android development. I am trying to use the following code

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.