-2

I want to show imformation of the newwork server on the listview. when I click some item, it will searchs the network again, return some data, show them on the Dialog. I used two AsyncTasks to realize it. But, when I click the item twice(click the item once is ok), it broken. I debugged and found that the second time it even not step into the itemclicklistener method at all. Can't fixed the bug... Any help is greatly appreciated. Here is parts of the codes. firstly onitemclicklistener

private class lvVoteItemOnItemClickListener implements AdapterView.OnItemClickListener {
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                                long arg3) {
            HashMap<String, String> map = (HashMap<String, String>) lvVoteItem.getItemAtPosition(arg2);
            if (clickID != Integer.parseInt(map.get("id"))) {
                clickID = Integer.parseInt(map.get("id"));
                new VoteAccountTask().execute(map.get("id"));
            } else {
                new AlertDialog.Builder(VoteSummaryActivity.this).setTitle(res)
                        .setIcon(null)
                        .setView(null)
                        .show();
                String temp = "";
            }

        }
    }

secondly, the show dialog AsyncTask

public class VoteAccountTask extends AsyncTask<String, Void, String> {

    protected String doInBackground(String... param) {
            return searchVoteAccountWebservice(Integer.parseInt(param[0]));
    }

    @Override
    protected void onPostExecute(String result) {
        //votedetail.itemID + signal + votedetail.vID + signal + votedetail.itemName + signal + votedetail.ifUserDefine + signal + votedetail.creater +signal + votedetail.createDate
        super.onPostExecute(result);
        res = setStringsByWebString(result, VoteSummaryActivity.this.getString(R.string.datasetserStr1), VoteSummaryActivity.this.getString(R.string.datasetserStr2));
        new AlertDialog.Builder(VoteSummaryActivity.this).setTitle(res)
                .setIcon(null)
                .setView(null)
                .show();
    }
}
Sudheesh R
  • 1,767
  • 3
  • 23
  • 43
bluehale
  • 7
  • 2

1 Answers1

0

Asynctask's are simply be executed without checking previous executions. Does not block UI. So your button, textView or anything clickable can fire an asynctask every time you click.

There is two method I would apply in same situations;

  1. Show Progress Dialog
  2. Set the item clickable=false at preExecute method and then set true at postExecute
Serhat Türkman
  • 373
  • 2
  • 11
  • Serhat Türkman, Thank you for your help. I tried your advice. Set the item clickable=false. But the problem still exists. I can't click the item the seconds. Click the first time it will pop up the dialog, the seconds it just exits the Activity. – bluehale Nov 14 '17 at 14:24
  • Asynctask's onPostExecute to pop up the AlertDialog, but found that it can't pop up the dialog again. Stil not found the reason. – bluehale Nov 14 '17 at 14:38