I\'m adding a listener to an EditText field to appropriately format the number to currency in real time.
loanText.addTextChangedListener(new TextWatc
public class MainActivity extends Activity {
EditText et;
TextWatcher tw;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et=(EditText) findViewById(R.id.et);
tw=new TextWatcher(){
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
}
@Override
public void afterTextChanged(Editable s) {
et.removeTextChangedListener(tw);
et.setText(Math.random()+"");//add your logic here
et.addTextChangedListener(tw);
}};
et.addTextChangedListener(tw);
}
} This is a Simple solution.