I am using the below code in my application.
Button button = new Button(this);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ProgressDialog pd = new ProgressDialog(v.getContext());
pd.setTitle("Please wait.......");
pd.show();
// some task which will take minimum 2 or 3 seconds
// e.g. parsing XML file
pd.dismiss();
}
});
I thought according to above code, when i click the button the progress dialog has to be displayed on screen, but its not displaying. Why i don’t know.
But if i remove pd.dismiss() its displaying, that also after button released only.
If i put any infinite loop in place of my task also, its not displaying progress dialog.
Is my code correct ? If anybody knows solution to my requirement please reply to this post.
Thanks.
use the AsychTask class for just write your code into the inBackground() method and show the progress using onUpdateProgress() and dismiss on onPostExecute()
here is the example links
http://developer.android.com/reference/android/os/AsyncTask.html
http://www.vogella.de/articles/AndroidPerformance/article.html