How I can add Native Ads admob in ListView

1,964 views
Skip to first unread message

Abdellatif El Bakali

unread,
Nov 29, 2016, 8:25:26 AM11/29/16
to Google Mobile Ads SDK Developers

 */
public class QuoteAdapter extends BaseAdapter {

   private ArrayList<Quote> data;
   private Context mContext;
   private LayoutInflater l_Inflater;
   private boolean isExpand = false;
   
   public QuoteAdapter(Context context, ArrayList<Quote> data) {
      this.data = data;
      this.mContext = context;
      l_Inflater = LayoutInflater.from(context);
   }
   /* (non-Javadoc)
    * @see android.widget.Adapter#getCount()
    */
   @Override
   public int getCount() {
      // TODO Auto-generated method stub
      return data.size();
   }

   /* (non-Javadoc)
    * @see android.widget.Adapter#getItem(int)
    */
   @Override
   public Object getItem(int pos) {
      // TODO Auto-generated method stub
      return data.get(pos);
   }

   /* (non-Javadoc)
    * @see android.widget.Adapter#getItemId(int)
    */
   @Override
   public long getItemId(int position) {
      // TODO Auto-generated method stub
      return position;
   }

   /* (non-Javadoc)
    * @see android.widget.Adapter#getView(int, android.view.View, android.view.ViewGroup)
    */
   @Override
   public View getView(final int position, View convertView, ViewGroup parent) {
      // TODO Auto-generated method stub
      ViewHolder holder;
      final Quote quote;
      quote = data.get(position);

         if (convertView == null) {
            convertView = l_Inflater.inflate(R.layout.quote_index_body, null);
            holder = new ViewHolder();

            holder.quote = (TextView)convertView.findViewById(R.id.qi_content);
            holder.fav = (CheckBox)convertView.findViewById(R.id.qi_fav_cbx);
            convertView.setTag(holder);
         }
         else {
            holder = (ViewHolder) convertView.getTag();
         }
         
         if (quote.getIs_favourist()==1) {
            holder.fav.setChecked(true);
         }else if(quote.getIs_favourist()==0){
            holder.fav.setChecked(false);
         }
         
         holder.fav.setOnClickListener(new OnClickListener() {
           
            @Override
            public void onClick(View v) {
               // TODO Auto-generated method stub
               onClickCheckBoxListener.OnClick(v, quote,position);
            }
         });
         
         WriteLog.d("ThangTB", "is expand = "+this.isExpand);
         if (!this.isExpand) {
            holder.quote.setMaxLines(2);
            holder.quote.setEllipsize(TruncateAt.END);
         }else{
            holder.quote.setMaxLines(30);
            holder.quote.setEllipsize(null);
         }
            holder.quote.setText(Html.fromHtml(quote.getBody()));


      /*
      if (convertView == null) {
         convertView = l_Inflater.inflate(R.layout.native_ad_adapter, null);
         NativeExpressAdView adView = (NativeExpressAdView)convertView.findViewById(R.id.adView);
         AdRequest adRequest = new AdRequest.Builder().build();
         adView.loadAd(adRequest);
      }
      else {
         convertView.getTag();
      }*/

      return convertView;
   }
   
   static class ViewHolder{
      TextView quote;
      CheckBox fav;
   }

   
   /**
    * @param data the data to set
    */
   public void setData(ArrayList<Quote> data) {
      this.data = data;
   }
   
   /**
    * @param isExpand the isExpand to set
    */
   public void setExpand(boolean isExpand) {
      this.isExpand = isExpand;
   }
   /**
    * @return the isExpand
    */
   public boolean isExpand() {
      return isExpand;
   }

   /* (non-Javadoc)
    * @see android.widget.BaseAdapter#notifyDataSetChanged()
    */
   @Override
   public void notifyDataSetChanged() {
      // TODO Auto-generated method stub
      super.notifyDataSetChanged();
   }
   
   //interface Onclick checbox
   public interface OnClickCheckBoxListener{
      public void OnClick(View v, Quote item, int pos);
   }
   
   OnClickCheckBoxListener onClickCheckBoxListener;
   
   /**
    * Set onclick image event
    * @param onClickcheckboxListener
    */
   public void setOnClickCheckBoxListener(OnClickCheckBoxListener onClickCheckBoxListener) {
      this.onClickCheckBoxListener = onClickCheckBoxListener;
   }
}

Help Me Please how i can add Ads Native listView in my code Adapter .?

Vu Chau (Mobile Ads SDK Team)

unread,
Nov 29, 2016, 10:35:06 AM11/29/16
to Google Mobile Ads SDK Developers
Hi Abdellatif,

We have two native ads (express and advanced) examples using RecyclerView and ListView here for your reference.

Regards,

Vu Chau
Mobile Ads SDK Team

Hammad Tariq

unread,
Dec 21, 2017, 11:40:57 PM12/21/17
to Google Mobile Ads SDK Developers
Express Ads are now deprecated, you can use Advanced Native AdMob Ads.
Follow below link for more details.
Reply all
Reply to author
Forward
0 new messages