Reputation: 731
I'm a having a listview, of type dialog pop-up. When i click on the item of the listview, i want loading progress bar to be displayed. Below is the listview code.
public AdapterView.OnItemClickListener getOnItemClickListener() {
return new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
// ProgressDialog dialog;
// dialog = ProgressDialog.show(view.getContext(), "Please wait..", "Loading data", true);
// dialog.setCancelable(false);
// dialog.show();
HashSet sometable= new HashSet();
sometable.add(i);
if (getContext() == null) return;
Intent output = new Intent();
final IData data = (IData) adapterView.getItemAtPosition(i);
//check if its myself
if((data.get("FIRST_NAME")==null)&&(data.get("LAST_NAME")==null))
output.putExtra("User","");
else{
output.putExtra("User", (String) data.get("ASSIGNEE_GUID"));
output.putExtra("userName", (String) data.get("FIRST_NAME") + " " + (String) data.get("LAST_NAME"));
//new cancelPending((Activity) getContext(),data).execute();
AssigneABO.SyncSubordinateCalendar((String) data.get("ASSIGNEE_GUID"), view.getContext());
//new MyTask(MainActivity.this).execute((Void) null);
}
Activity activity = (Activity) getContext() ;
activity.setResult(Activity.RESULT_OK,output);
activity.finish();
}
};
}
When i click on the items of the listview, starts the async task to get the data. In that async task's onprexcute method i'm calling the progress dialog as below.
public static class SyncApplicationTask extends AsyncTask<String, Context, Boolean> {
Context context;
ProgressDialog progress;// = new ProgressDialog(context);
public SyncApplicationTask(Context mcontext) {
super();
context = mcontext;
progress = new ProgressDialog(context);
}
@Override
protected void onPreExecute() {
progress.setMessage(context.getString(R.string.Sync));
progress.setTitle(R.string.sync_msg);
progress.setCanceledOnTouchOutside(false);
progress.setCancelable(false);
progress.setIndeterminate(true);
progress.show();
if (!Util.hasActiveNetworkConnection(context)) {
Util.alertMessageDialog(context, R.string.network_connection_unavailable_message);
return;
}
if (SynchronizationManager.getInstance().isSyncAllCategoryGroupActive()) {
Util.alertMessageDialog(context, R.string.synchronization_still_active);
return;
}
if (!ConnectionManager.getInstance().isServerConnected()) {
ConnectionManager.getInstance().stopServerConnection(60);
boolean isStarted = ConnectionManager.getInstance()
.startServerConnection(60); // 2 mins time out
Log.v("Connection started : ", Boolean.valueOf(isStarted)
.toString());
if (!isStarted) {
Util.alertMessageDialog(context, R.string.connection_server_lost_message);
return;
}
}
}
@Override
protected Boolean doInBackground(String... syncGroups) {
try {
SAPReXDB.synchronize(syncGroups[0]);
return true;
}catch (Exception Ex)
{ Log.v("Erron on sync: ", Ex.toString());
return false;
}
}
@Override
protected void onPostExecute(final Boolean c) {
progress.dismiss();
if(!c)
Util.alertMessageDialog(context, R.string.sync_progress_failed);
}
}
But it is displaying behind the dialog listview. I want it to display above the dialog listview. What am'i doing wrong. Can you please suggest me on this. Thank you.
Upvotes: 0
Views: 1189
Reputation: 569
With which Context do you create ProgressDialog?
GUI position & order issues can happen when you do not use normal Activity Context, but using your specific View's context or Application Context.
Upvotes: 1