XML : How to automatically add thousand separators in EditText?

I want to Automatically add thousand separators in EditText while user types using the last solution in this topic.

I've already made a seperate java file as a class as described and pasted the given code. but I have no idea how to modify my activity code in order to achieve the desired effects.

Here's my XML code:

          <EditText          android:layout_width="wrap_content"          android:layout_height="wrap_content"          android:inputType="number"          android:id="@+id/editText"          android:layout_weight="1"/>    

and my related Activity is like:

  public class CostofHearingActivity extends AppCompatActivity {    public void calculate(View view){    // some calculations      }    @Override  protected void onCreate(Bundle savedInstanceState) {      super.onCreate(savedInstanceState);      setContentView(R.layout.activity_costof_hearing);      Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);      setSupportActionBar(toolbar);        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);      fab.setOnClickListener(new View.OnClickListener() {          @Override          public void onClick(View view) {              Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)                      .setAction("Action", null).show();          }      });  }    

}

any help would be appreciated.

No comments:

Post a Comment