I have Login Screen in my app in which I made a method which enable and disable EditText button according to Internet availability scenario is something like that:- Description: The login/create an account button should get enabled when internet is available and disabled when internet is not available, this should be done in real time, currently it seems like internet availability is being checked on key press event. Now, considering two scenario
We enter all the details and then enable the internet. Expected Result:login/create an account button should be enabled. Actual Result: login/create an account button remains disabled.
Internet is available, We enter all the required details, the button gets enabled. Now, if the internet gets disabled Expected Result: Button should be disabled Actual Result: Button remains enabled
here is my code:-
public void checkFieldsForEmpty() {// this method check Edit text is empty or not
m_LoginBtn = (AppCompatButton) findViewById(R.id.btn_Login);// finding Id login botton
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
// check mobile Internet connectivity
if (NetworkUtil.isConnected(getApplicationContext())) {
// if mobile number and password are Emoty
if (s_szMobileNumber.equals("") || s_szPassword.equals("")) {// check if mobile and password is empty ..
m_LoginBtn.setEnabled(false);// make Login button disabled
m_LoginBtn.setBackgroundColor(Color.rgb(192, 192, 192));// color of login button
} else {
m_LoginBtn.setEnabled(true);// make login button enabled
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 {
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));
}