我想在editText中的一个千分隔符(,),当我在editText键入。 之后,我会对数字进行一些操作,然后在千位分隔符(,)的TextView中显示结果。“编辑文本和TextView”格式与千位分隔符(,)在android
这是我的代码:
public class Mainactivity extends Activity {
/** Called when the activity is first created. */
EditText edt;
TextView txt;
Button btn;
OnClickListener myclick = new OnClickListener() {
@Override
public void onClick(View arg0) {
// my calculation
double num1 = Double.parseDouble(edt.getText().toString());
double num2 = num1 + 7;
txt.setText("" + num2);
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
edt = (EditText) findViewById(R.id.edt);
txt = (TextView) findViewById(R.id.txt);
btn = (Button) findViewById(R.id.btn);
btn.setOnClickListener(myclick);
}
}
你可以使用 [答案http://stackoverflow.com/questions/12338445/how-to-automatically-添加千隔板-AS-数是输入合的EditText] [1] [1]:http://stackoverflow.com/questions/12338445/how-to-automatically-add -千-separators-as-number-is-input-in-edittext – JoaoBiriba 2014-09-13 13:32:05