ProgressDialog onClick not working.. here is my code .. Basically i want to show loading dialog when user submits login form and waits for response
public class LoginLayout extends MenuActivity {
ProgressDialog progress;
EditText un,pw;
TextView error;
Button ok;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
un=(EditText)findViewById(R.id.et_un);
pw=(EditText)findViewById(R.id.et_pw);
ok=(Button)findViewById(R.id.btn_login);
error=(TextView)findViewById(R.id.tv_error);
ok.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
progress = ProgressDialog.show(LoginLayout.this, "Login","please...wait",true);
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("username", un.getText().toString()));
postParameters.add(new BasicNameValuePair("password", pw.getText().toString()));
String response = null;
try {
response = CustomHttpClient.executeHttpPost("http://www.mysite.com/api/login.php", postParameters);
String res=response.toString();
res= res.replaceAll("\\s+","");
progress.dismiss();
if(res.equals("1"))
error.setText("Correct Username or Password");
else
error.setText("Sorry!! Incorrect Username or Password");
} catch (Exception e) {
un.setText(e.toString());
}
}
});
}
}
You have to use Hanlders or AsyncTask. There are numerous questions regarding this here. Try to follow the below snippet,
Do this in your onCreate()
And now use a thread to upload files to server. Modify this piece of code,
If not go for AsyncTask,
Here are few links,
http://www.vogella.de/articles/AndroidPerformance/article.html
http://labs.makemachine.net/2010/05/android-asynctask-example/
http://developer.android.com/reference/android/os/AsyncTask.html