The game has 4 character action lists. When you click on each item of each list, the action is performed. To repeat the action once again, you need to wait (the waiting time is different everywhere, let's call it timeout); When you click on an item in the background, a horizontal progress bar starts to act. When the progress bar reaches the end, the action can be repeated. The time of progression depends on the timeout.

In general, I hang the listener on the list ...

lv_inspiration.setOnItemClickListener(new OnItemClickListener(){ @Override public void onItemClick(AdapterView<?> p1, View p2, int p3, long p4) { b = (ProgressBar)p2.findViewById(R.id.progress_bar_item); cdt = new CountDownTimer(100000,1000) { @Override public void onTick(long millisUntilFinished) { i++; b.setProgress(i); } @Override public void onFinish() { i=0; } }; cdt.start(); } }); 

And I get such a picture - when you click on the item, the progress bar starts and starts working. If I wait for him to finish and click on the second, then nothing happens. If you press the second one while the first one is running, the first one stops, the second one continues the progress from the point where the first one stops and with double speed. In addition, when scrolling fly progress. What's wrong? Help, maybe there is some article? Or maybe someone has seen such an implementation somewhere?

UPD Changed the code of the getView() method in your SimpleAdapter , now other items will work when the progress bar reaches the end. But, if you click on the item and scroll through the list so that the clicked item is not visible, the progress bar continues to work in other items, that is, it "jumps". And if, without waiting for the end of the first to click on the second, then the first one stops, the second continues to progress with double speed. Well, and so on with this effect. Help, what's wrong? And what the hell is with this ListView?

  • That is, it turns out that the progress bar switches in its execution to a new item? How does the progress bar get new progress? - Ivan Vovk pm
  • @Ivan Vovk, yes)) switches to the clicked) I don’t know how to make the list keep all progress bars in items: (so that nothing goes anywhere and all progress bars work independently of each other. Progress bars get progress through CountDownTimer. Code in question - Flippy

2 answers 2

Create a separate class for the progress bar and make it irrevocable:

 public class Helper { ProgressDialog progressDialog = null; // Пользователь ожидает окончания загрузки данных public void showProgress(Context context,String text) { if (progressDialog == null) { try { progressDialog = ProgressDialog.show(context, "", text); progressDialog.setCancelable(false); } catch (Exception e) { } } } public void hideProgress() { if (progressDialog != null) { progressDialog.dismiss(); progressDialog = null; } } } 

Now the beginning and end of the progress bar depends on your logic. Run the execution of the item and immediately progress bar, as the item will work to cut down the progress bar.

  • @Herrgott, meaning to initialize in advance?) - Flippy
  • @ Sergey You have definitely confused something here in the comments :) - Herrgott
  • @Herrgott, what are you talking about? :) - Flippy
  • @ Sergey, my question is below, but you ask me about it, and mine are asking others - Herrgott

create a CountDownTimer outside the listener and check if it is running, do nothing, if it is not running, run with timeout parameters, etc.

And it is better to initialize the View in advance, I mean b = (ProgressBar)p2.findViewById(R.id.progress_bar_item); inside the listener