-3
我有一個名爲移動和密碼的編輯文本字段,情景是,當應用程序啓動它時出現錯誤文本,當我在相應的字段中輸入文本時,並且在完成編輯文本後檢查值如果正確,然後移動其他顯示該領域的錯誤。如何在android中輸入文本時在編輯文本中檢查值?
代碼: -
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));
}
}
請更新代碼 – Nitin