2017-01-07 10 views
0

예를 들어 주기로 한 번에이 코드를 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 
      } 
     } 
    });