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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:24:25+00:00 2026-05-28T15:24:25+00:00

Using my onEditTextchanger. It works fine when the user inputs 100000, in the EditText

  • 0

Using my onEditTextchanger. It works fine when the user inputs 100000, in the EditText box it shows $100,000.00 as the user types. Which is correct.
The problem is however if I try to display a numeric keyboard rather than a Qwerty keyboard. By adding in the XML I add android: inputType=”numberDecimal” I lose the formatting of $ and the, and the EditText displays like 100000.00. I have noticed this happens if I change the InputType to Number or Decimal as well. I have attached the code.
Any ideas? Again Thanks in advance for your help.

XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Number1"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<EditText
    android:id="@+id/txta"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="0" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Number2" />

<EditText
    android:id="@+id/txtb"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="0" />

<TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Number3" />

<TextView
    android:id="@+id/txtc"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<TextView
    android:id="@+id/textView4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Your Answer is"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
    android:id="@+id/txtd"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<Button
    android:id="@+id/buttonCalc"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Calculate" />

Java

public class CalcTestActivity extends Activity {
    private EditText txta;
    private EditText txtb;
    private TextView txtc;
    private TextView txtd;


    private double a = 0;
    private double b = 0;
    private double c = 0;
    private double d = 0;

    private Button buttonCalc;

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

        initControls();

        txta.addTextChangedListener(new CurrencyTextWatcher());
        txtb.addTextChangedListener(new CurrencyTextWatcher());

    }   



    private void initControls() {

        txta = (EditText)findViewById(R.id.txta);
        txtb = (EditText)findViewById(R.id.txtb);
        txtc = (TextView)findViewById(R.id.txtc);
        txtd = (TextView)findViewById(R.id.txtd);

        buttonCalc = (Button)findViewById(R.id.buttonCalc);
        buttonCalc.setOnClickListener(new Button.OnClickListener() {

            public void onClick(View v) {calculate(); }});}

    private void calculate() {

        a=Double.parseDouble(txta.getText().toString().replace("$", "").replace(",", ""));
        b=Double.parseDouble(txtb.getText().toString().replace("$", "").replace(",", ""));
        c=Math.round(a*.88);                
        txtc.setText(GlobalMoney.FormatValue(c));
        d=Math.round((a*.87)+(b*.61)*(c*.25));
        txtd.setText(GlobalMoney.FormatValue(d));
    }


}

TextWatcher

import java.text.NumberFormat;
import android.text.Editable;
import android.text.TextWatcher;

public class CurrencyTextWatcher implements TextWatcher {

    boolean mEditing;

    public CurrencyTextWatcher() {
        mEditing = false;
    }

    public void afterTextChanged(Editable s) {
        // TODO Auto-generated method stub
        if(!mEditing) {
            mEditing = true;

            String digits = s.toString().replaceAll("\\D", "");
            NumberFormat nf = NumberFormat.getCurrencyInstance();
            try{
                String formatted = nf.format(Double.parseDouble(digits)/100);
                s.replace(0, s.length(), formatted);
            } catch (NumberFormatException nfe) {
                s.clear();
            }

            mEditing = false;
        } 
    }
    public void beforeTextChanged(CharSequence s, int start, int count,
            int after) {
        // TODO Auto-generated method stub

    }

    public void onTextChanged(CharSequence s, int start, int before, int count) {
        // TODO Auto-generated method stub

    }

}
  • 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-28T15:24:26+00:00Added an answer on May 28, 2026 at 3:24 pm

    By default, inputType=”numberDecimal” doesn’t accept any special characters except .(dot). May be you need to do some hack to make this work. There is an interesting SO discussion to hack in special character ‘,’. You may try that to have $ symbol. Here is link.

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

Sidebar

Related Questions

Using the C# Facebook SDK 5.0.3 everything works fine whit the client.Get(/me). But when
Using C#, I need a class called User that has a username, password, active
Currently I am using my onEditTextchanger. To format my currency. What I am wondering
Using android 2.3.3, I have a background Service which has a socket connection. There's
Using the http://www.ifans.com/forums/showthread.php?t=132024 post from another question i am allowing the user to enter
Using MVC2 I have an AJAX form which is posting to a bound model.
Using Delphi 2010. I am looking for (possibly) a function or procedure which can
Using online interfaces to a version control system is a nice way to have
Using PyObjC , you can use Python to write Cocoa applications for OS X.
Using ASP.NET MVC there are situations (such as form submission) that may require a

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.