使用Facebook在Android中实现原生广告

时间:2016-08-23 10:26:25

标签: android facebook android-recyclerview adapter native-ads

使用Facebook在Android中实现原生广告,我在我的recyclerview适配器中使用Facebook广告,我发现我的广告放在适配器中的位置但是如何???

   private final Context mContext;
private final List<MsgListData> msgListDatas;

private NativeAd nativeAd;

int AD_TYPE = 0;
int CONTENT_TYPE = 1;

public MessageDetailAdapter(Context context, List<MsgListData> msgListDatas) {
    this.mContext = context;
    this.msgListDatas = msgListDatas;

}

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

    ViewHolder holder;

    if (viewType == AD_TYPE) {
     //native add load hear but hou?????        


        } else {
        View view = LayoutInflater.from(mContext).inflate(R.layout.row_msgdetail_item, parent, false);
        holder = new ViewHolder(view);
    }
    return holder;
}

@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
    if (position % 6 != 3) {
        holder.txtDes.setText(msgListDatas.get(position).getDetails());
        int color = Color.parseColor(msgListDatas.get(position).getColor_code());

        holder.card_view.setBackgroundColor(color);
        holder.card_view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mContext, MsgSwipActivity.class);
                intent.putExtra("CATID", msgListDatas.get(position).getCategory());
                intent.putExtra("ID", msgListDatas.get(position).getId());
                mContext.startActivity(intent);
            }
        });
    }
}

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

@Override
public int getItemViewType(int position) {
    if (position % 6 == 3)
        return AD_TYPE;
    return CONTENT_TYPE;
}

public class ViewHolder extends RecyclerView.ViewHolder {
    //Restaurant
    public TextView txtDes;
    public CardView card_view;

    private ViewHolder(View itemView) {
        super(itemView);
        this.txtDes = (TextView) itemView.findViewById(R.id.txtDes);
        this.card_view = (CardView) itemView.findViewById(R.id.card_view);

    }
}

这是我的适配器中的facebook原生广告加载代码。但它不起作用。

0 个答案:

没有答案