nck nck - 1 year ago 103
Android Question

How to put many objects in a scroll view entry in android?

I want to create a database where I get some data like name, two boolean represented by a toggle button and a checklist and list everything in a scroll view like in figure 1. Also I want to add a "delete" and "update" button in the same entry of the scrollview.

I've seen you can put a horizontal LinearLayout in the vertical Linearlayour which is created in the

, in this way I can put the text and buttons in the same line. But when I do that I can't add another line for the toggle and checkbox information and also I can't put a common background to the whole entry.

Could anyone give me a hint of how should I address this problem? I've tried to solve it in the xml main layout just to get an idea to then translate it to the code, but I can't get it to work.

enter image description here

Answer Source

You only need to add another LinearLayout as a container for every list item:

- ScrollView
    - LinearLayout (vertical) -> List container
        - LinearLayout (vertical) -> Item container
            - LinearLayout (horizontal)
                ...some elements....
            - End of LinearLayout (horizontal)
            - LinearLayout (horizontal)
                ...more elements....
            - End of LinearLayout (horizontal)
        - End of LinearLayout (vertical) -> Item container
        ...More item containers...
    - End of LinearLayout (vertical) -> List container
- End of ScrollView

This is not the exact layout as in your image but you should solve it following this pattern.

Despite this, as others said in their comments this can be achieved in a more efficient way using a ListView or better a RecyclerView.

I can't show you a real example right now, I will do it later if you need.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download