1

So I did some research and testing of using a listview in a scrollview, and as a lot of people may know this is supposedly bad to do, since they both scroll. It also means I can't show the complete listview as it will wrap to be smaller.

I have seen places which re change the height of the listview to fix this problem but again most people say that it isn't preferred.

What I would like to know though is what is the preferred way of making a nonscrollable listview like view? Basically I want the exact same as the listview but obviously non scrolled and the height based on its contents. I would prefer to work with the layout in as much XML as possible, and I would like to be able to send my array list to it to view on screen. Unfortunately either my search skills are quite dull, as I haven't been able to find anywhere that really explains the preferred method so I thought I would ask here.

Thanks for your help.

<>Clarification Information
I thought I would put this here in case it will help, first off I basically want to show an image, with a list of comments (each one has an author and a text) below it, the comments themselves are obtained from an array and can change. I want the whole page to be scrollable though so I can either view more comments or go back up to the image.

John McKenzie
  • 420
  • 6
  • 16
  • You could make a [RecyclerView](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.html) (it is a newer alternative to the ListView) with an adapter which handles multiple item types. Take a look at [this method](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.Adapter.html#getItemViewType(int)). Actually let me write this as an answer with some more details. – Samuil Yanovski Feb 12 '15 at 12:08

1 Answers1

1

Using a RecyclerView and an adapter supporting multiple item types you could make a list which shows an image on top and several comments below it. Generally you'd have to check what item corresponds to each position - in your case on position 0 you have an image and in every other position you'd have a comment. Then in your adapter's onCreateViewHolder and onBindViewHolder you would check the item type and handle them differently.

You could take a look at this answer for a short example. Let me know if you'd need any other details and/ or sample codes to get the idea. :)

Community
  • 1
  • 1
Samuil Yanovski
  • 2,837
  • 17
  • 19
  • I would go for this solution as well. Along the lines of this suggestion is the old listview's headerview, which can be applied in the recyclerview. More on this [here] (http://stackoverflow.com/questions/26448717/android-5-0-add-header-footer-to-a-recyclerview). – Joao Sousa Feb 12 '15 at 12:24