android - Error "Incompatible types" while adding NativeAds in recyclerView -


i trying add native ads in recyclerview. following tutorial. looks recyclerviewadapter little bit different have them.

package com.comp.app.adapters;  public class recyclerviewadapter extends  recyclerview.adapter<recyclerviewadapter.recyclerviewholder> {  private context context; private constants constants; private string androidid; private string id; private arraylist<cardsettergetter> arraylist = new arraylist<cardsettergetter>(); private arraylist<string> favouriteitemlist = new arraylist<string>(); private int totalcount; private static final int menu_item_view_type = 0 ; private static final int ad_view_type = 1;  public recyclerviewadapter(context context, arraylist<cardsettergetter> arraylist, arraylist<string> favouriteitemlist, int totalcount) {     this.arraylist = arraylist;     this.context = context;     this.arraylist = arraylist;     this.favouriteitemlist = favouriteitemlist;     this.totalcount = totalcount;  }  @override public long getitemid(int position) {     sethasstableids(true);     return super.getitemid(position); }  @override public recyclerviewadapter.recyclerviewholder oncreateviewholder(viewgroup parent, int viewtype) {      switch (viewtype){          case ad_view_type:             view nativeexpresslayoutview = layoutinflater.from(parent.getcontext())                     .inflate(r.layout.native_express_ad_container, parent, false);             return new nativeexpressadviewholder(nativeexpresslayoutview); // incompatible types.  required: com.comp.app.adapters.recyclerviewadapter.recyclerviewholder                    found: com.comp.app.adapters.recyclerviewadapter.nativeexpressadviewholder          case menu_item_view_type:          default:             view view = layoutinflater.from(parent.getcontext()).inflate(r.layout.cards, parent, false);             return new recyclerviewholder(view);     } }   @override public void onbindviewholder(final recyclerviewholder holder, final int position) {      int viewtype = getitemviewtype(position);      switch (viewtype){          case ad_view_type:             nativeexpressadviewholder nativeexpressholder = (nativeexpressadviewholder)holder; //inconvertible types;  cannot case 'com.comp.app.adapters.recyclerviewadapter.recyclerviewholder' 'com.comp.app.adapters.recyclerviewadapter.nativeexpressadviewholder'             nativeexpressadview adview = (nativeexpressadview)holder.getposition(); //inconvertible types; cannot cast 'int' 'com.google.android.gms.ads.nativeexpressadview              viewgroup adcardview = (viewgroup)nativeexpressholder.itemview;             adcardview.removeallviews();              if(adview.getparent() != null){                 ((viewgroup)adview.getparent()).removeview(adview);             }              adcardview.addview(adview);             break;          case menu_item_view_type:          default:             string card_image;             cardsettergetter cardsettergetter;             cardsettergetter = arraylist.get(position);              card_image = constants.serverip.concat(cardsettergetter.getimageurl());             holder.cardsettergetter = cardsettergetter;             holder.title.settext(cardsettergetter.getimagetitle()); //set title              cardsettergetter.gettag();              pointf focuspoint = new pointf(0.5f, 0f);             // app populates focus point              holder.image // set image                     .gethierarchy()                     .setactualimagefocuspoint(focuspoint);             holder.image.setimageuri(uri.parse(card_image));              if (cardsettergetter.getfavourite().equals("yes")) {                 holder.favourite_button.setimageresource(r.drawable.ic_bookmark_black_36dp);              } else {                 holder.favourite_button.setimageresource(r.drawable.ic_bookmark_border_black_36dp);             }     }  }  public class nativeexpressadviewholder extends recyclerview.viewholder{     nativeexpressadviewholder(view view){         super(view);     } }  @override public int getitemviewtype(int position){     return (position % 8 == 0)? ad_view_type: menu_item_view_type; }  @override public int getitemcount() {      return arraylist.size(); }  public class recyclerviewholder extends recyclerview.viewholder {      textview title;     relativelayout relativelayout;     relativelayout carddescription;     simpledraweeview image;     //imageview image;     imageview favourite_button;     cardsettergetter cardsettergetter;     imageview share;       private recyclerviewholder(view itemview) {         super(itemview);         title = (textview) itemview.findviewbyid(r.id.image_title);         relativelayout = (relativelayout) itemview.findviewbyid(r.id.activity_dash_board);         carddescription = (relativelayout) itemview.findviewbyid(r.id.card_details);         image = (simpledraweeview) itemview.findviewbyid(r.id.image);         favourite_button = (imageview) itemview.findviewbyid(r.id.favourite_button);         share = (imageview) itemview.findviewbyid(r.id.share);          image.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view view) {                  activity activity = (activity) context;                 saveinfo(constants.serverip.concat(cardsettergetter.getimageurl()), cardsettergetter.getimageid(), cardsettergetter.getdescription(), cardsettergetter.getimagetitle(), cardsettergetter.getfavourite());                 intent = new intent().setclass(context, detailsimageviewactivity.class);                 i.setflags(intent.flag_activity_new_task | intent.flag_activity_multiple_task);                 context.startactivity(i);                 activity.overridependingtransition(r.anim.pull_from_right, r.anim.pull_out_to_right);             }         });         favourite_button.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view view) {                  favouriteitemlist.add(title.gettext().tostring());                  if (cardsettergetter.getfavourite().equals("yes")) {                     id = cardsettergetter.getimageid();                     system.out.println("imageid" + id);                     getdata();                     requestwithsomehttpheaders1();                     system.out.println("header1");                     favourite_button.setimageresource(r.drawable.ic_bookmark_border_black_36dp);                     cardsettergetter.setfavorite("no");                      toast.maketext(context, "bookmark removed", toast.length_short).show();                  } else {                      id = cardsettergetter.getimageid();                     system.out.println("imageid" + id);                     getdata();                     system.out.println("header2");                     requestwithsomehttpheaders2();                     favourite_button.setimageresource(r.drawable.ic_bookmark_black_36dp);                     cardsettergetter.setfavorite("yes");                      toast.maketext(context, "bookmark added", toast.length_short).show();                  }              }         });         share.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view view) {                  string sharebody = constants.serverip.concat(cardsettergetter.getimageurl());                 intent sharingintent = new intent(android.content.intent.action_send);                 sharingintent.settype("text/plain");                 sharingintent.putextra(android.content.intent.extra_subject, "hey, check out infographic/fact on app.");                 sharingintent.putextra(android.content.intent.extra_text, sharebody);                 context.startactivity(intent.createchooser(sharingintent, "share image using"));              }         });       } }  private void getdata() {     try {         sharedpreferences sharedpref = context.getsharedpreferences("mobileid", context.mode_private);         androidid = sharedpref.getstring("mobileid", "");     } catch (exception e) {      }   }  private void requestwithsomehttpheaders2() {     requestqueue queue = volley.newrequestqueue(context);     stringrequest postrequest = new stringrequest(request.method.post, "my url",             new response.listener<string>() {                 @override                 public void onresponse(string response) {                     system.out.println(response);                 }               },              new response.errorlistener() {                 @override                 public void onerrorresponse(volleyerror error) {                     // todo auto-generated method stub                     log.d("error", "error => " + error.tostring());                     networkresponse networkresponse = error.networkresponse;                     if (networkresponse != null) {                         log.e("volley", "error. http status code:" + networkresponse.statuscode);                     }                      if (error instanceof timeouterror) {                         log.e("volley", "timeouterror");                     } else if (error instanceof noconnectionerror) {                         log.e("volley", "noconnectionerror");                     } else if (error instanceof authfailureerror) {                         log.e("volley", "authfailureerror");                     } else if (error instanceof servererror) {                         log.e("volley", "servererror");                     } else if (error instanceof networkerror) {                         log.e("volley", "networkerror");                     } else if (error instanceof parseerror) {                         log.e("volley", "parseerror");                     }                 }               }      )      {         @override         protected map<string, string> getparams() throws authfailureerror {             // return super.getparams();             map<string, string> params = new hashmap<string, string>();             params.put("device_id", androidid);             params.put("image_id", id);             params.put("favourite", "yes");              return params;          }     };     queue.add(postrequest); }  private void requestwithsomehttpheaders1() {     requestqueue queue = volley.newrequestqueue(context);     stringrequest postrequest = new stringrequest(request.method.post, "my url",             new response.listener<string>() {                 @override                 public void onresponse(string response) {                       system.out.println(response);                 }               },              new response.errorlistener() {                 @override                 public void onerrorresponse(volleyerror error) {                     // todo auto-generated method stub                     log.d("error", "error => " + error.tostring());                     networkresponse networkresponse = error.networkresponse;                     if (networkresponse != null) {                         log.e("volley", "error. http status code:" + networkresponse.statuscode);                     }                      if (error instanceof timeouterror) {                         log.e("volley", "timeouterror");                     } else if (error instanceof noconnectionerror) {                         log.e("volley", "noconnectionerror");                     } else if (error instanceof authfailureerror) {                         log.e("volley", "authfailureerror");                     } else if (error instanceof servererror) {                         log.e("volley", "servererror");                     } else if (error instanceof networkerror) {                         log.e("volley", "networkerror");                     } else if (error instanceof parseerror) {                         log.e("volley", "parseerror");                     }                 }               }      )      {         @override         protected map<string, string> getparams() throws authfailureerror {             map<string, string> params = new hashmap<string, string>();             params.put("device_id", androidid);             params.put("image_id", id);             params.put("favourite", "no");              return params;          }     };     queue.add(postrequest); }  private void saveinfo(string imageurl, string imageid, string imagedescription, string imagetitle, string favourite) {     sharedpreferences sharedpref = context.getsharedpreferences("imageinfo", context.mode_private);     sharedpreferences.editor editor = sharedpref.edit();     editor.putstring("imageurl", imageurl);     editor.putstring("imageid", imageid);     editor.putstring("imagedescription", imagedescription);     editor.putstring("imagetitle", imagetitle);     editor.putstring("favourite", favourite);     editor.apply();   }   } 

this code in activity

private list listitems;

private void addnativeexpressads(){ (int = 0; i<listitems.size(); += 5){     nativeexpressadview adview = new nativeexpressadview(this);     adview.setadsize(new adsize(320,150));     adview.setadunitid("my adunitid");     adview.loadad(new adrequest.builder().build());     listitems.add(i,adview); //wrong 2nd argument type, 'com.google.android.gms.ads.nativeexpressadview', required:'app.appname.cardsettergetter' } } 


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -