2

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.

5 Answers 5

3

Disable "next" button until the data is loaded completly or the process is canceled.

Sign up to request clarification or add additional context in comments.

Comments

3

after clicking the button, do setEnabled(false) to this button, to disable multiple clicks

Comments

2

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.

Comments

0

After click put the button setEnabled(false) and in the loadAndShowNextActivity() dismiss the pDialog.dismiss()

Comments

0
dialogButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialogButton.setEnabled(false); .... dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialogInterface) { dialogButton.setEnabled(true); } }); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.