0

I am reaching out for help as I am exhausted from watching Video to Video and Group to Group for help. Whenever I am embedding the codes, the app is continually crashing.

In the Recyclerview + Cardview with GridLayout.I am trying to embed Admob Native Ads on Home Page, and interstitial ads when someone clicks on the book cover, and when the ad is closed he can see the detailed description. In the detailed description want to embed native ads two to three times.

package com.demotxt.myapp.recyclerview;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.android.gms.ads.InterstitialAd;

import java.util.List;


public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.MyViewHolder> {

    private Context mContext ;
    private List<Book> mData ;


    public RecyclerViewAdapter(Context mContext, List<Book> mData) {
        this.mContext = mContext;
        this.mData = mData;

    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view ;
        LayoutInflater mInflater = LayoutInflater.from(mContext);
        view = mInflater.inflate(R.layout.cardveiw_item_book,parent,false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {

        holder.tv_book_title.setText(mData.get(position).getTitle());
        holder.img_book_thumbnail.setImageResource(mData.get(position).getThumbnail());
        holder.cardView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent(mContext,Book_Activity.class);

                // passing data to the book activity
                intent.putExtra("Title",mData.get(position).getTitle());
                intent.putExtra("Description",mData.get(position).getDescription());
                intent.putExtra("Thumbnail",mData.get(position).getThumbnail());

                // start the activity
                mContext.startActivity(intent);



            }
        });



    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder {

        TextView tv_book_title;
        ImageView img_book_thumbnail;
        CardView cardView ;

        public MyViewHolder(View itemView) {
            super(itemView);

            tv_book_title = (TextView) itemView.findViewById(R.id.book_title_id) ;
            img_book_thumbnail = (ImageView) itemView.findViewById(R.id.book_img_id);
            cardView = (CardView) itemView.findViewById(R.id.cardview_id);


        }
    }


};

package com.demotxt.myapp.recyclerview;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.ads.MobileAds;

import java.util.ArrayList;
import java.util.List;


public class MainActivity extends AppCompatActivity {

    List<Book> lstBook ;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        MobileAds.initialize(this,
                getString(R.string.admob_app_id));

        lstBook = new ArrayList<>();


        lstBook.add(new Book("The Vegitarian","Categorie Book",getString(R.string.description_thevigitarian),R.drawable.thevigitarian));
        lstBook.add(new Book("Capitalism","Economics", getString(R.string.description_capitalism),R.drawable.capitalism));
        lstBook.add(new Book("Fooled by Randomness","Economics",getString(R.string.description_fooledby),R.drawable.fooledby));
        lstBook.add(new Book("Antifragile","Economics",getString(R.string.description_antifragile),R.drawable.antifragile));
        lstBook.add(new Book("Freakonomics","Economics",getString(R.string.description_freaknomics),R.drawable.freaknomics));
        lstBook.add(new Book("The Wild Robot","Categorie Book",getString(R.string.description_thewildrobot),R.drawable.thewildrobot));
        lstBook.add(new Book("Maria Semples","Categorie Book",getString(R.string.description_mariasemples),R.drawable.mariasemples));
        lstBook.add(new Book("The Martian","Categorie Book",getString(R.string.description_themartian),R.drawable.themartian));
        lstBook.add(new Book("He Died with...","Categorie Book",getString(R.string.description_hediedwith),R.drawable.hediedwith));
        lstBook.add(new Book("The Vegitarian","Categorie Book",getString(R.string.description_thevigitarian),R.drawable.thevigitarian));
        lstBook.add(new Book("The Wild Robot","Categorie Book",getString(R.string.description_thewildrobot),R.drawable.thewildrobot));
        lstBook.add(new Book("Maria Semples","Categorie Book",getString(R.string.description_thevigitarian),R.drawable.mariasemples));
        lstBook.add(new Book("The Martian","Categorie Book",getString(R.string.description_themartian),R.drawable.themartian));
        lstBook.add(new Book("He Died with...","Categorie Book",getString(R.string.description_hediedwith),R.drawable.hediedwith));
        lstBook.add(new Book("The Vegitarian","Categorie Book",getString(R.string.description_thevigitarian),R.drawable.thevigitarian));
        lstBook.add(new Book("The Wild Robot","Categorie Book",getString(R.string.description_thewildrobot),R.drawable.thewildrobot));
        lstBook.add(new Book("Maria Semples","Categorie Book",getString(R.string.description_mariasemples),R.drawable.mariasemples));
        lstBook.add(new Book("The Martian","Categorie Book",getString(R.string.description_themartian),R.drawable.themartian));
        lstBook.add(new Book("He Died with...","Categorie Book",getString(R.string.description_hediedwith),R.drawable.hediedwith));

        RecyclerView myrv = (RecyclerView) findViewById(R.id.recyclerview_id);
        RecyclerViewAdapter myAdapter = new RecyclerViewAdapter(this,lstBook);
        myrv.setLayoutManager(new GridLayoutManager(this,2));
        myrv.setAdapter(myAdapter);


    }
}
uSamvad
  • 1
  • 1
  • Can you be more precise as you want tutorials or you stuck with some problem? – Ashutosh Sagar Oct 11 '18 at 11:32
  • First of all thanks for the reply Ashutosh... Codes or tutorials.. – uSamvad Oct 11 '18 at 11:57
  • As I am unable to figure out myself that's why I am reaching out for help from Experts like you. – uSamvad Oct 11 '18 at 12:06
  • Please check out the Add Mob Documentation. Its a very good documentation. https://developers.google.com/admob/android/quick-start Some of the usual problems could be wrong key or the screen space is not sufficient to display ads in that case it'll not be displayed. – Ashutosh Sagar Oct 12 '18 at 05:28
  • Thanks, Ashutosh. Frustrated with the crashing, I am just trying to put native ads between the detailed description. If you can help me with the code for that???? Thanks in advance for ur time and efforts.. – uSamvad Oct 12 '18 at 09:33

0 Answers0