Can I use adapters without having ListViews?

28 views Asked by At

I receive lots of data from the backend that I need to display in 2 sections of my app in different ways, such as drawing real time graphs. 1 of the sections in question is a rectangle, that is just an elaborate scrollbar (drag the frame you see in the image below to change the set of channels currently displayed).

Without going too much into detail, I have a list of channels and for each channel I generate a line inside that rectangle. It should end up looking like this:

enter image description here

The color of each line also depends on the type and state of each channel so each line has a bit of logic, meaning it must be a view instead of just a png. That rectangle cannot be scrolled, it's a static view. So I was thinking, is there a way to use an adapter (Something like an ArrayAdapter) without a ListView? I want to have a LinearLayout and inside that LinearLayout I want a line to be created for each channel object inside the List. Should I just make a foreach loop?

1

There are 1 answers

0
MaDudeeK On

"ListView and ListAdapter have been obsolete for several years. They were replaced by RecyclerView and RecyclerView.Adapter. For this case, since your content is not scrollable, a LinearLayout (or a Row() in Compose UI) seems fine. An adapter seems unnecessary, as those are for cases where you need scrolling and need to be able to create the visual representations of a large data set on the fly as the user scrolls." - @CommonsWare

In the case above, the appropriate solution would be to for each loop the List to create and add Views to a LinearLayout. Adapters are unnecessary, since in this scenario scrolling is unwanted.