2017-01-07 4 views
0

このコードを、例えば、サイクルで10回繰り返すのではなく、 、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 
      } 
     } 
    }); 
関連する問題