avoid multiple clicks on a button
<p>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.</p>

<p>Am doing it this way:</p>

<pre><code>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 &lt; items.size() - 1) {   
                ind++;
                loadAndShowNextActivity();
            }
        } else if (v == previous) {
            if (ind &gt; 0) {
                ind--;
                loadAndShowNextActivity();
            }
        }

    } catch (Exception e) {

        Log.e("Error", "--.OnClink Message" + e.toString());
        e.printStackTrace();
    }
}
</code></pre>

<p>Where am i going wrong. How can i avoid multiple clicks or avoid never ending dialog. ANy help is appreciated.</p>
