What To Use Instead Of Recyclerview If Not Recycling Items
I am a beginner and I have seen many tutorials on how to create a list using RecyclerView, but I can't find any how to use a list without recycling. I have a list of 3 items. what
Solution 1:
Another way to look at you list would be as simple items (since there are only 3). You can just add items to a LinearLayout
with orientation as vertical
.
You can even go further and create a common item layout XML, and using a for loop, inflate your LinearLayout
. Example:
//create item class@AllArgsConstructor@GetterprivatestaticclassItem {
privateint iconId;
private String mainText;
private String detailsText;
}
// create itemprivateItemITEM_1=newItem(R.drawable.some_drawable, getString(R.string.some_string), getString(R.string.some_string));
//add item to an arrayList (only add what you want that logged in user to see :D)
itemList.add((ITEM_1))
//layout you want to add to@BindView(R.id.content) LinearLayout layoutToAddTo;
LayoutInflaterinflater= LayoutInflater.from(getContext());
for (Item item : itemList) { // a list which holds all your Items//XML that the Item class matches.Viewcard= inflater.inflate(R.layout.card, layoutToAddTo, false);
bindContent(card, item);
card.setOnClickListener(__ -> /* set your listener */));
layoutToAddTo.addView(card);
}
//bind your contentprivatevoidbindContent(View view, Item item) {
((ImageView) view.findViewById(R.id.card_icon)).setImageDrawable(ContextCompat.getDrawable(context, item.getIconId());
((TextView) view.findViewById(R.id.card_main_text)).setText(item.getMainText());
((TextView) view.findViewById(R.id.card_details_text)).setText(item.getDetailsText());
}
Best for few items, otherwise try to use Recycler View.
Solution 2:
You can use ListView
if you don't want to recycle the list item.
Here ListView
Post a Comment for "What To Use Instead Of Recyclerview If Not Recycling Items"