我通过例如 for 循环而不是重复10次(D1 d1,D2 d2,... 。,D10 d10):
//
// -------------- DIAMETRO 1 -----------------------------------
//
final EditText D1 = (EditText)findViewById(R.id.d1);
int d1 = mast.getInstance().getd1();
Log.d("Diametro 1 =", Integer.toString(d1));
D1.setText(Integer.toString(d1));
//
// Perdita del focus del diametro 1
//
D1.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
/* When focus is lost check that the text field
* has valid values.
*/
if (!hasFocus) {
String strD1=D1.getText().toString();
mast.getInstance().setd1(Integer.valueOf(strD1));
}
}
});
答案 0 :(得分:0)
更多细节here!
EditText txtEdit = (EditText) findViewById(R.id.edittxt);
txtEdit.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
// code to execute when EditText loses focus
}
}
});