I searched for long without success about making this piece of code in one shot by means, for instance, of a for cycle rather than repeating it 10 times (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));
}
}
});
More detail here!