如何限制点之后的字符数(显示在我的 TextView 中) 看到 2 种方式会很棒:在 java 中,实际上在 TextView XML 中(如果可能的话)谢谢!
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
inivVars();
}
private void inivVars(){...}
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.bCount:
try{
checkT1 = et1.getText().toString();
checkT2 = et2.getText().toString();
checkK1 = ek1.getText().toString();
det1 = Float.parseFloat(checkT1);
det2 = Float.parseFloat(checkT2);
dek1 = Float.parseFloat(checkK1);
float x = det2/(det1/100)/100*dek1;
String sx = String.valueOf(x);
text.setText(sx);
text.setTextColor(Color.BLUE);
}catch(Exception e){
Toast t = Toast.makeText(CivilProtectActivity.this, "enter all values or use suitable '.'", Toast.LENGTH_LONG);
t.show();
}
break;
case R.id.bHide:
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(et1.getWindowToken(), 0);
et1.setText("");
et2.setText("");
ek1.setText("");
text.setText("");
break;
}}}
和显示数据的 TextView XML
<TextView
android:id="@+id/tvShowA"
android:layout_width="95dp"
android:layout_height="95dp"
android:textSize="22dp"
android:hint="X"
android:background="@drawable/sun"
android:gravity="center"
/>