I'm writing an Android application which requires the user to login. I have a "username" and "password" EditText fields and also a "Submit" button.
When testing in the emulator (and on a phone), the app appears to 'lock up' when the user hits "Submit". It hasn't actually crashed or anything like that, it's just locked whilst the connection to the server is made (and then it advances the user to the next view if their login is correct).
This isn't very cosmetically pleasing as some users may think the app has locked up if their connection is slow and the login doesn't process for a few seconds..
To avoid this I want to have a ProgressBar which will appear just to let the user know something is happening and the app hasn't locked up!
Here's my code:
private OnClickListener listenerOne = new OnClickListener() {
public void onClick(View v) {
Button submitButton = (Button)findViewById(R.id.submit);
submitButton.setVisibility(8); //Make submit button invisible
ProgressBar progressBar = (ProgressBar)findViewById(R.id.progressbar);
progressBar.setVisibility(0); //Make progress bar visible. It's in the same position as the submit button
login(); // do the login server stuff
// the problem is that thenew visibility doesn't happen until the login() is called...
}
};
I've ordered the code so that it makes the submit invisible, then makes the progress bar visible, then does the login (so the progress bar will be there twirling around whilst the app connects to the login server). However, it's not working out how I intended - it's seemingly skipping over the setVisibility code and just calling the login method. It must be setting the visibility of the submit and progress bar items but it doesn't happen before the login method does its stuff as it just locks up like usual and the items never actually get hidden/shown until the login method has completed!!
Any help would be much appreciated. Sorry for the essay!