2Stoned 2Stoned - 1 year ago 97
Android Question

How to create programmaticlly textview in RecyclerView.ViewHolder

Trying to figure out how to add dynamically changing number of textviews to my viewholder.

Im getting (int) counter from my server, which represent the number of proprties in the viewholder. each viewholder have different number of properties.

Any idea how to implement this?

Answer Source

In your ViewHolder store the new TextViews in a List, and add each TextView to the cell's itemView in the ViewHolder. Should look similar to the code below:

ViewGroup viewGroup = (ViewGroup)itemView.findViewById(R.id.your_viewgroups_id); //Usually a LinearLayout or RelativeLayout
List<TextView> textViews = new LinkedList<>();
for (int i = 0; i < count; i++) {
     TextView textView = new TextView(context)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download