Filter Input in Real-Time?
<p>I have an EditText (accepts 0-9) with a listener. I want to grab input as it's entered, apply a calculation, and display it in the same EditText box.</p>

<p>The box initially displays $0.00. When the user inputs a 2, I want to grab that from the box, parse it to remove the $ and decimal, convert it to an int... divide it by 100 and put a $ in front of it. After setText, it should display $0.02. If they then press 5, I'll grab it, parse it, end up with 25, do the math and it should display $0.25, etc.</p>

<p>I don't know if this is the best way, I'm open to new ideas. Here is my current code:</p>

<pre><code>mEditPrice.addTextChangedListener(new TextWatcher(){
        DecimalFormat dec = new DecimalFormat("0.00");
        @Override
        public void afterTextChanged(Editable arg0) {
        }
        @Override
        public void beforeTextChanged(CharSequence s, int start,
                int count, int after) {
        }
        @Override
        public void onTextChanged(CharSequence s, int start,
                int before, int count) {
            String userInput = mEditPrice.getText().toString().replaceAll("[^\\d]", "");
            int userInputInt = Integer.parseInt(userInput);
            mEditPrice.setText("$"+dec.format(userInputInt / 100));
        }
</code></pre>
