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: androidsmartly

I am a Tech Enthusiast who likes to work on new Ideas. Sharing knowledge on Android, Marketing, Startups and More.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s