Reputation: 367
I've a ListView with a list of item retrieving with JSON and i want to show a ProgressDialog on item click.
listNews.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View v, int position,
long arg3) {
ProgressDialog dialog;
dialog = ProgressDialog.show(v.getContext(), "Please wait..", "Loading data", true);
dialog.setCancelable(false);
dialog.show();
News n = (News)listNews.getItemAtPosition(position);
Intent myIntent = new Intent(v.getContext(), SingleActivity.class);
myIntent.putExtra("actu_id", n.ID);
dialog.dismiss();
startActivityForResult(myIntent, 0);
}
});
ProgressDialog not showing... Same problem when I define this progressDialog in OnCreate in SingleActivity.class
Can you help me ?
Sorry for my english ...
Upvotes: 0
Views: 507
Reputation: 2232
It's a problem related with your workflow. Since you're doing additional tasks on the UI thread, the ProgressDialog doesn't get to be shown.
You should either spawn a thread for doing the extra work, then dismiss your dialog and launch your new Intent with runOnUiThread() or with a Handler.
Although, the best option would be using AsyncTask, showing your ProgressDialog onPreExecute(), doing your work in doInBackground() and then dismissing it onPostExecute() and launching your new activity.
Upvotes: 0