-2

Please suggest me how to set value in edit Text and Text view as a percentage format and currency format

if i enter in edit text 12345678.28 then it's give me currency as $12,345,678.28 and if i enter percentage as 10.25 it's give me 10.25%

Dhaval Shah
  • 59
  • 2
  • 11

2 Answers2

1

you can achieve it by using TextWatcher or inputFilter

private String current = "";
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
    if(!s.toString().equals(current)){
       [your_edittext].removeTextChangedListener(this);

       String cleanString = s.toString().replaceAll("[$,.]", "");

       double parsed = Double.parseDouble(cleanString);
       String formated = NumberFormat.getCurrencyInstance().format((parsed/100));

       current = formated;
       [your_edittext].setText(formated);
       [your_edittext].setSelection(formated.length());

       [your_edittext].addTextChangedListener(this);
    }
}
Community
  • 1
  • 1
Nambi
  • 11,944
  • 3
  • 37
  • 49
0

If you enter value in edit text append string like this..

 Edittext et;


  et.setonclickListener = new clicklistener()
 { 
  et.settext("$" + "And get text from your edit text");

 }
Roadies
  • 3,309
  • 2
  • 30
  • 46