Answer the question
In order to leave comments, you need to log in
How to make adapter take data from ArrayList in reverse order?
There is an adapter that takes data from an ArrayList. You need to either make the adapter take objects from the arraylist in reverse order, or sort the ListView itself in a similar way. Thanks in advance
Answer the question
In order to leave comments, you need to log in
ArrayList<String> List = new ArrayList<>(); // Исходный ArrayList
ArrayList<String> newList = new ArrayList<>();
List.add("Первый"); // Заполнил List
List.add("Второй");
List.add("Третий");
for (int i=List.size()-1; i>=0; i--) // Перевернул List и засунул
newList.add(List.get(i)); // в newList
for(String str : newList)
System.out.println(str);
public class MyAdapter extends ArrayAdapter<String> {
private List<String> list;
public MyAdapter(Context context, int resource, List<String> list) {
super(context, resource, list);
this.list=list;
}
@Override
public int getCount() {
return list.size();
}
@Override
public String getItem(int position) {
return list.get((position-list.size())*-1-1);
}
}
Derivate from ArrayList and override get method? Or add a new getReverse method? I didn’t quite catch your problem, the difficulty is that you can’t change the ArrayList or the adapter?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question