I have a Fragment class on a button click I should display a tableview with contents,which is taking a time span of 4 seconds or more depending on the contents to be displayed. So I thought to show a progressDialog after button click and dismiss after my method execution.
But the process is appearing after a delay,like after the tableview appears.So there is a delay in showing the progress bar. I have tried so many approaches still no luck.
Below is the code I am trying.
@Override
public void onClick(final View v) {
switch (v.getId()) {
case R.id.btn_spreadsheetAddTable: {
//Some code
}
break;
case R.id.btn_horizontalAddTable: {
AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
return null;
}
@Override
protected void onPreExecute() {
mProgressDialog = new ProgressDialog(getActivity());
mProgressDialog.setTitle("Processing...");
mProgressDialog.setMessage("Please wait.");
mProgressDialog.setCancelable(false);
mProgressDialog.setIndeterminate(true);
mProgressDialog.show();
displayAddTableView(editIsEnabled);
}
@Override
protected void onPostExecute(Void result) {
if (mProgressDialog!=null) {
mProgressDialog.dismiss();
}
}
};
task.execute((Void[])null);
editIsEnabled = false;
}
private void displayAddTableView(boolean editEnabled) {
//A code to display dynamic table with dynamic data
}
}
I have been tried the following urls also:
android - Progressbar Late Loading when button click
Loading Dialog, Progress Dialog on Button Click
ProgressDialog doesn't appear immediately
Please help me on this.Thank you.