Here is the problem
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
progressDialog = ProgressDialog.show(ContactMainActivity.this, "",
"Loading. Please wait...",true);
setContentView(R.layout.contactlist);
contactListView=getListView();
contactListView.setTextFilterEnabled(true);
contactListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
Thread t = new Thread() {
public void run() {
try{
runOnUiThread(new Runnable() {
public void run() {
//stuff that updates ui
queryAllRawContacts();
progressDialog.dismiss();
}
});
registerForContextMenu(contactListView);
} catch (Exception e) {
Log.e("tag", e.getMessage());
}
// dismiss the progress dialog
}
};
t.start();
}
this is onCreate method of my activity class.
This activity actually one tab of a tabwidget. So when I click this tab and run the activity, it waits about 2 seconds and then show progress dialog like 10 millisec and updates the UI with the data. and dismiss progress dialog. What I would like to achieve is that as soon as the tab is clicked, the progress dialog will be shown and it takes about 2-3 seconds to load data. after loading and updating the UI the progress bar will be dismissed.
Thanks
queryAllRawContacts()needs to not be run on the UI thread. Change your code to the following: