2016-06-07 3 views
-3

모바일 및 비밀번호로 이름이 지정된 편집 텍스트 필드가 있습니다. 시나리오는 앱 실행시 오류 텍스트와 함께 표시되며, 해당 필드에 텍스트를 입력 할 때 텍스트를 편집하고 텍스트를 완료 한 후 값이 올바른지 확인한 다음 다른 것으로 이동하십시오. 해당 필드에 오류가 있습니다.android에서 텍스트를 입력하는 동안 텍스트 편집에서 가치를 확인하는 방법은 무엇입니까?

코드 : - 부울 "fromBroadcast는"중 초기화 된 경우, 혹은 그 오류 메시지를 설정하기 전에 점검 할 필요가 무엇인지를 알 수있는에서 그 상태를 얻는 곳

private final BroadcastReceiver m_oOtpReceiver = new BroadcastReceiver() {// creating broadcast to receive otp sent by server from Inbox... 
    @Override 
    public void onReceive(Context context, Intent intent) {// on receive method to read OTP sent by server 
     checkFieldsForEmpty(true);// check whether edit text is empty or not 

    } 
}; 
private TextWatcher m_oTextWatcher = new TextWatcher() {// making object of TextWathcher class 
    @Override 
    public void beforeTextChanged(CharSequence s, int start, int count, int after) { 

    } 

    @Override 
    public void onTextChanged(CharSequence s, int start, int before, int count) {// when text change in Edit tEXT 

    } 

    @Override 
    public void afterTextChanged(Editable s) { 
     checkFieldsForEmpty(false);// CHECK LOGIN BUTTON DISABLED AND ENABED 
    } 
}; 

/*This method check Edit text is empty or not*/ 
public void checkFieldsForEmpty(boolean fromBroadcast) {// this method check Edit text is empty or not 

    s_szMobileNumber = m_InputMobile.getText().toString().trim();// get mobile number from edit Text 
    s_szPassword = m_InputPassword.getText().toString().trim();// get password from edit text 

    if (NetworkUtil.isConnected(getApplicationContext())) { 
     // if mobile number and password are Emoty 
     if (s_szMobileNumber != null && s_szMobileNumber.length() > 7 && s_szMobileNumber.length() < 15) {// check if mobile and password is empty .. 
      if (s_szPassword.length() >= 4 && s_szPassword.length() <= 8) { 
       m_LoginBtn.setEnabled(true);// make Login button disabled 

       m_LoginBtn.setBackgroundColor(Color.rgb(0, 80, 147));// set background color on eabled 
       m_LoginBtn.setOnClickListener(new View.OnClickListener() {// onclick listener on Login Button 
        @Override 
        public void onClick(View v) { 
         postLoginDataToServer(); 

        } 
       }); 
      } else { 
        if (!fromBroadcast) { 

         m_InputPassword.setError("Password must be between 4 to 8 characters long"); 
        } 
       m_LoginBtn.setEnabled(false);// make login button enabled 
       m_LoginBtn.setBackgroundColor(Color.rgb(192, 192, 192));// color of login button 
      } 

     } else { 
       if (!fromBroadcast) { 
        m_InputMobile.setError("Mobile number must be between 7 to 15 characters long"); 
       } 

      m_LoginBtn.setEnabled(false);// make login button enabled 
      m_LoginBtn.setBackgroundColor(Color.rgb(192, 192, 192));// color of login button 

     } 

    } else { 
     try { 
      CSnackBar.getInstance().showSnackBarError(findViewById(R.id.mainLayout), "No Internet Connection Available", getApplicationContext()); 

     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
     m_LoginBtn.setEnabled(false); 
     m_LoginBtn.setBackgroundColor(Color.rgb(192, 192, 192)); 
    } 


} 

답변

0

내가 볼 수 없습니다 textView에. 내가 읽은 것에서는 "fromBroadcast"를 확인하기 위해 if 문을 사용할 필요가 없다고 가정합니다. 코드는 코드없이 작동해야합니다. 오류 메시지와 함께 응용 프로그램을 시작하고 오류 메시지를 원하지 않으면 입력을 위해 m_InputPassword 대신 s_szPassword를 확인해야하며 올바른 단어가 먼저 포함되도록 s_szPassword를 초기화하여 오류 메시지가 처음에는 나타나지 않도록 할 수 있습니다.

+0

코드를 업데이트하십시오. – Nitin

관련 문제