Answer the question
In order to leave comments, you need to log in
Dynamic size of an array of java objects?
android.leocardz.com/multiple-layout-listview
Made according to the lesson, everything is fine.
But how to define a dynamic array? I don't know beforehand how many elements there will be.
Tried it in different ways, but I'm still a noob in Java.
PS Yes, I know that RecyclerView is better, but ListView is also suitable for my purposes.
My goal is simple: to display data from the table in a more or less beautiful form. I write for myself. Along the way, getting acquainted with ANDROID DEVELOPMENT.
Answer the question
In order to leave comments, you need to log in
Solution (if anyone needs it):
//Создаю:
List<List<String>> list = new ArrayList<>();
//Добавляю в цикле так:
list.add(new ArrayList());
list.get(list.size()-1).add(text);
list.get(list.size()-1).add(text2+"");
//Затем(после работы цикла) заполняю:
final ListViewItem[] items = new ListViewItem[list.size()];
li=0;
for (List item : list) {
items[li] = new ListViewItem(item.get(0),Integer.parseInt(item.get(1)));
li++;
}
Dude, use collections. I think ArrayList can suit you well for this task. And also, learn Java well, then it will be easier to breathe in Android development.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question