G
G
Good Samaritan2019-02-16 18:00:19
Android
Good Samaritan, 2019-02-16 18:00:19

How to properly build an application on listview?

Good evening. My application consists of the following elements. The main screen is a listview with a list of various topics (no more than 20 list items). When you click on any element, there is a transition to another list in which there are statements on the selected topic (also no more than 20 elements). What is the best way to implement this? I have the following solution in my head:
Load a listview with themes into the main activity, when you click on it, a second activity is called into which the id of the list of statements to be loaded is passed as an intent. That is, put these statements in the onCreate method

ArrayList <String> list1 = new ArrayList <String>();
        list1.add("Высказывани №1 оывталывоатывлотывломтывломтылвомтылвомтылвомтывломтывломтывлмоты");
        list1.add("Высказывани №2 оывталывоатывлотывломтывломтылвомтылвомтылвомтывломтывломтывлмоты");
        list1.add("Высказывани №3 оывталывоатывлотывломтывломтылвомтылвомтылвомтывломтывломтывлмоты");
        .....
        list1.add("Высказывани №20 оывталывоатывлотывломтывломтылвомтылвомтылвомтывломтывломтывлмоты");
        
        ArrayList <String> list2 = new ArrayList <String>();
        list2.add("Высказывани №1 оывталывоатывлотывломтывломтылвомтылвомтылвомтывломтывломтывлмоты");
        list2.add("Высказывани №2 оывталывоатывлотывломтывломтылвомтылвомтылвомтывломтывломтывлмоты");
        list2.add("Высказывани №3 оывталывоатывлотывломтывломтылвомтылвомтылвомтывломтывломтывлмоты");
        .....
        list2.add("Высказывани №20 оывталывоатывлотывломтывломтылвомтылвомтылвомтывломтывломтывлмоты");
        
        ......

        ArrayList <String> list20 = new ArrayList <String>();
        list20.add("Высказывани №1 оывталывоатывлотывломтывломтылвомтылвомтылвомтывломтывломтывлмоты");
        list20.add("Высказывани №2 оывталывоатывлотывломтывломтылвомтылвомтылвомтывломтывломтывлмоты");
        list20.add("Высказывани №3 оывталывоатывлотывломтывломтылвомтылвомтылвомтывломтывломтывлмоты");
        .....
        list20.add("Высказывани №20 оывталывоатывлотывломтывломтылвомтылвомтылвомтывломтывломтывлмоты");

And depending on the id of the one that came from the main list, pass one or another list to the adapter
. I'm sure that this is not the right way. Place as much text where the code should be. Tell.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Developer, 2019-02-16
@samodum

As an option, you can add several txt files to assets, in which each line is an element of the list.
At the start of the activity, read each file into its own list and then transfer these lists to the adapters for the ListView

I
illuzor, 2019-02-16
@iLLuzor

You can correctly make an application with ListView as follows:
1) Forget about ListView;
2) Use RecyclerView.
In general, it is strange to hammer the list by hand. The list can be received from the server if the application is client-server. If not, you can transfer an array of strings to resources.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question