Luke Casey
Luke Casey

Reputation: 135

What is the correct alternative to using ListViews in a NestedScrollView?

I'm creating a detail view for a Dictionary entry. The basic structure is as follows: A dictionary item can have 1 or many 'Meanings'. Each of these 'Meanings' can further have 0 or many 'Field of Applications', 'Part of Speech', and 'Dialect' values. There are other similar sections for a dictionary item as well such as example sentences.

Due to the size and structure varying based on a query result, it seems to me like the best way to do this would be to have multiple ListViews as follows:

Detail view components mockup

I realise that putting ListViews inside ScrollViews is a bad idea, and Google themselves say you shouldn't do it, so what is the 'best practice' way to accomplish something like this?

I've thought of the following solutions, none of which seem ideal:

  1. Use a single TextView instead of a ListView, and use new line characters to separate data rows. This feels very hacky and makes formatting specific parts of a row difficult.
  2. Replace the ListViews with LinearLayouts, then programmatically insert TextViews within them as needed.
  3. Create a custom ListView which is not scrollable.

This seems like a very common use case for a detail view, yet I can't find any concrete answer on how to deal with this.

Upvotes: 1

Views: 820

Answers (1)

Tomislav Novoselec
Tomislav Novoselec

Reputation: 4620

You can replace your ListView with RecyclerView (and adapter as well= and call

recyclerView.setNestedScrollingEnabled(false);

which will enable smooth nested scrolling.

Upvotes: 2

Related Questions