Android Basics – Learn how to use the onBindViewHolder method to bind the data to the View

So far you have created an Adapter for the RecyclerView. You have also added a View Holder.

In order to display data you need to write code to the onBindViewHolder method. This method will map the data to the Card View.

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    CardView cardView = holder.mCardView;
    TextView cardText = (TextView) cardView.findViewById(R.id.cardTextId);
    cardText.setText(textData[position]);
}

Source code is available here.

Author: codesmartly

I am Enthusiastic about Learning new things and sharing my Knowledge. I like programming and have a pretty good background in Computer Science.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s