I wrote my adapter for ListView in which there is a checkbox , textview , progressbar . There is a class that implements the file download over the network.

I need to send each selected link from the ListView to download, along with a progressbar link, to display the download. But here is bad luck. I don’t know how to get a progressbar on a position in the ListView .

Here is the source code for my adapter.

Here is the source code for the container class with which it is filled.

Help me please implement the adapter method:

ProgressBar getProgressBar (int position) {// ??????? }

There may be a lot of code, but please help. I do not want to do crutches. Already brought beauty with the display of download progress and multi-threading.

  • 2
    Add source code to the body of the question, not to individual resources. - Vladimir Glinskikh
  • 2
    Not every item in the list has a progress bar. If you have 100 elements, but only 4 are visible at the same time, then there are no more than 6 pieces of progress bars. - Vladyslav Matviienko

2 answers 2

I think it's easier for you to make a single model class. In the class you describe the type (it is better to make enum), and Object is the object itself. Implement an ArrayList<КЛАСС МОДЕЛЬ> Add these models to the list, and where you need to process something, compare type from the model class and you know exactly what it will be for Object from the model class. Or use instanceof but he is known to be the slowest in java. This is your idea.

If you need to write the code. Or I do not quite understand what you mean.

Ok, let's start, I will take such simple examples.

Let's start with a small example.

We create our listings, in them you will describe your types.

 package javaapplication21; public enum myType { checkBox, miscBox } 

Create a model that will be used in ArrayList or where you need it.

 public class myModel { myType type = null; Object value = null; public myModel(myType type, Object value){ this.type = type; this.value = value; } @Override public String toString(){ if(type==null)return null; return type.toString(); } } 

You can then add all the standard functions such as eguals(сравнение двух моделей) .

Now we go where we will use it.

 package javaapplication21; import java.util.ArrayList; public class JavaApplication21 { public static void main(String[] args) { ArrayList<myModel> models = new ArrayList<>(); models.add(new myModel(myType.checkBox, "Здесь ваш checkBox")); models.add(new myModel(myType.miscBox, "Здесь ваш miscBox")); //используем этот набор arraylist там где вам надо, пересылаете его и обрабатываете int a = 0; int max = models.size(); while(a!=max){ myModel model = models.get(a); if(model.type == myType.checkBox){ System.out.println("Я знаю что это checkBox"); } if(model.type == myType.miscBox){ System.out.println("Я знаю что это miscBox"); } a = a + 1; } } } 

Everything is very simple, I use this method everywhere.

  • I think you understood correctly, but I didn’t quite understand how to write it :) - T2skler
  • If you need to listen to what you click in ListVIew, here's an excellent developer.alexanderklimov.ru/android/views/listview.php instruction how to add a listener, if it is of course an android - Denis Kotlyarov

I have not played with android, but judging by this guide , everything is quite simple.

When initializing the ProgressBar call the following progressBar.setMax(objects.size()) method. Here we indicate the number of cells that will be processed. And then, in the course of execution, call the progressBar.setProgress(ЗЮ) , where we indicate the number of already processed cells.