Search code examples
androidandroid-recyclerviewandroid-dialogfragment

If recycler view is not recycled, is it inefficient to use recycler view?


enter image description here

I am making a screen like a picture. The background color is white, so you can't see it, but it's a dialog window. (The picture is a comment I entered arbitrarily)

As in the picture, the dialog consists of a RecyclerView. Up to 5 items can be created.

All the items are listed in the photo, but when i open the dialog for the first time, there is only one item, and when i press the enter key in the first comment, the next item is dynamically created.

Comments can only be entered with a maximum of one line.

The key here is that it has a maximum of 5 items unconditionally.

Very few items.

So there will be no scrolling and therefore no recycling is expected.

Is it okay to use Recycler View in this situation?

Some people say that there is no advantage to using RecyclerView as it is not recycled.

I used addView() as an alternative, but it doesn't work the way I want it to be because I wrote the code incorrectly.

Is there really no reason to use RecyclerView if the item is not recycled?

Or tell me a good idea for my function

(If you want, I will upload the code that used addView())


Solution

  • Yes I would say it is absolutely okay to use RecyclerView in this instance. It obviously is not built for this purpose and would generally take more time to implement than a simple solution as you mentioned with addView(View), however if the code is already written and it is working the way you want it to, I see no reason to over-complicate things.

    To address specifically your concern with efficiency, I am sure there will be a theoretical small performance hit, but I wouldn't recommend focusing time into optimisation if the payoff is small and there isn't a performance issue in the first place.

    Premature optimization is the root of all evil - Donald Knuth


    As a side note, in reference to the answer from @Primož Ivančič, there is no reason to use RecyclerView, but since you have already taken the time to implement it, there is probably no reason not to.