A
A
Andrey K2018-11-26 07:02:48
Android
Andrey K, 2018-11-26 07:02:48

Android: how to properly organize comments under an article?

Hello. I am a beginner android developer (self-taught). I'm making an application that has "posts" and comments below them. I met with the fundamental problems of organizing this type of pages, I ask for advice.
Task : create a page with an article at the top, an arbitrary number of comments below it. All this should scroll in a single block.
Possible solutions:
ListView under the article
If you place the block with the article and the ListView below it inside the ScrollView , the comments will scroll inside the ListView block, the article will not go to the top, because the ListView on the screen has a fixed height (calculated during the first rendering). You can track scrolling in the list and dynamically change the markup parameters, but this method fails, because it depends on the speed of the swipe...
Article in the ListView header element A ListView
is placed in the ScrollView, and a block with the article is dynamically added to its header.
The best option at the moment: the page scrolls naturally, a small hack is to embed a block in the header. Disadvantages:
* ListView is deprecated, and RecyclerView does not have a header element (it will have to be emulated).
* "reversed" concept: an article inside a list of comments, not comments inside an article.
LinearLayout instead of ListView
ScrollView + LinearLayout, the first element of which is the article, and comments are added "manually" below.
Pros: Natural scrolling, LinearLayout auto-height increases as comments are added. Disadvantages: You have to implement the functionality provided by the list adapter yourself (adding/changing/deleting elements).
Question: is there a way to create an "article-comments" markup with a list of comments managed through an adapter and with "natural" page scrolling; without hacks like embedding a block in the ListView header or programmatic scrolling.
ps You can say: "Use frameworks, bro." But I'm learning and I want to know all the mechanics, so I'm doing a lot of things from scratch.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Zagaevsky, 2018-11-26
@aakumykov

Take RecyclerView. You take AdapterDelegates from Hannes Dorfman. You make two kinds of elements. Profit.
You forget about the foliage, as if it never existed. You forget about adding an indefinite number of views to any layout except RecyclerView.

M
Mikhail Chvarkov, 2018-11-26
@KuSu

The option "Article in the ListView header element" is the most correct. You just make a RecyclerView and declare 2 types of markup in it - one for the article and one for the comment.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question