Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Recyclerview + Cardview with GridLayout + Different Activity | Android studio

In this Android post we are going to show how to use  Recyclerview + Cardview with GridLayout + Different Activity in Android studio.First of all Let's create Recyclerview + Cardview with GridLayout.Then create Different activities for different cards.

Watch below video until time 25.41 for First part .


Then let's create different Activities.(Book_Activities)Watch time 25.41 - 26.11
Let's say we all created 5 activities(eg:Book_Activity_1,Book_Activity_2,Book_Activity_3,Book_Activity_4,Book_Activity_5.......)


Then go to RecyclerViewAdapter.java file and search onBindViewHolder and edit like below code:
@Overridepublic void onBindViewHolder(MyViewHolder holder, final int position) {
    holder.tv_book_title.setText(mData.get(position).getTitle());
    holder.img_book_thumbnail.setImageResource(mData.get(position).getPhoto());
    holder.cardview.setOnClickListener(new View.OnClickListener() {
        @Override        public void onClick(View v) {
            Intent intent;
            switch (position){
                case 0:
                    intent = new Intent(mContext,Book_Activity_1.class);
                    mContext.startActivity(intent);
                    break;

                case 1 :
                    intent = new Intent(mContext,Book_Activity_2.class);
                    mContext.startActivity(intent);
                    break;

                case 2 :
                    intent = new Intent(mContext,Book_Activity_3.class);
                    mContext.startActivity(intent);
                    break;

                case 3 :
                    intent = new Intent(mContext,Book_Activity_4.class);
                    mContext.startActivity(intent);
                    break;

                case 4 :
                    intent = new Intent(mContext,Book_Activity_5.class);
                    mContext.startActivity(intent);
                    break;   }
        }
    });

}

Don't forget to add created classes names like Book_Activity_1,2,3.........That's all..... 


This post first appeared on GleanPost, please read the originial post: here

Share the post

Recyclerview + Cardview with GridLayout + Different Activity | Android studio

×

Subscribe to Gleanpost

Get updates delivered right to your inbox!

Thank you for your subscription

×