I have an application where in which i have two buttons, named ‘next’ and ‘previous’. These buttons are to navigate through the stories being loaded from a url. When the button is tapped the dialog appears to show “Please wait loading data”. When we tapp the next or previous button quite extravagantly, a never ending dialog appears on screen.
Am doing it this way:
public void onClick(View v) {
try {
pDialog = new ProgressDialog(StoriesListController.this);
pDialog.setIndeterminate(true);
pDialog.setIcon(R.drawable.icon_small);
pDialog.setCancelable(true);
if (isFavoriteList == true) {
pDialog.setMessage("Loading favorites...");
} else {
pDialog.setMessage("Loading data...");
}
pDialog.setTitle("Please wait");
pDialog.setOnCancelListener(new OnCancelListener() {
public void onCancel(DialogInterface arg0) {
if (cancelableHeavyWorker != null) {
cancelableHeavyWorker.setHandler(null);
}
finish();
}
});
pDialog.show();
if (v == next) {
if (ind < items.size() - 1) {
ind++;
loadAndShowNextActivity();
}
} else if (v == previous) {
if (ind > 0) {
ind--;
loadAndShowNextActivity();
}
}
} catch (Exception e) {
Log.e("Error", "--.OnClink Message" + e.toString());
e.printStackTrace();
}
}
Where am i going wrong. How can i avoid multiple clicks or avoid never ending dialog. ANy help is appreciated.
Alternatively to the other answers you could set a boolean variable to true when the button is clicked and set it to false when you’re done processing the click.
This way you can ignore multiple clicks and not having to disable the button possibly avoiding annoying flickering of the button.