Android : How to set ClickListener for Pop-Menu in Card View? -


i'm developing android music streaming application. have card views , each card view has pop menus (as shown in image) . want id of card clicked. albumadapter class extends recyclerview , can't set id of card clicked. showing error red lines.

enter image description here

the code have set having error inside lines..

albumsadapter.java..

public class albumsadapter extends recyclerview.adapter<albumsadapter.myviewholder> {      private context mcontext;     private list<album> albumlist;      public class myviewholder extends recyclerview.viewholder {         public textview title, count;         public imageview thumbnail, overflow;            public myviewholder(view view) {             super(view);             title = (textview) view.findviewbyid(r.id.title);             count = (textview) view.findviewbyid(r.id.count);             thumbnail = (imageview) view.findviewbyid(r.id.thumbnail);             overflow = (imageview) view.findviewbyid(r.id.overflow);         }     }       public albumsadapter(context mcontext, list<album> albumlist) {         this.mcontext = mcontext;         this.albumlist = albumlist;     }      @override     public myviewholder oncreateviewholder(viewgroup parent, int viewtype) {         view itemview = layoutinflater.from(parent.getcontext())                 .inflate(r.layout.album_card, parent, false);          return new myviewholder(itemview);     }      @override     public void onbindviewholder(final myviewholder holder, int position) {         album album = albumlist.get(position);         holder.title.settext(album.getname());         holder.count.settext(album.getnumofsongs() + " songs");          // loading album cover using glide library         glide.with(mcontext).load(album.getthumbnail()).into(holder.thumbnail);          holder.overflow.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view view) {                 showpopupmenu(holder.overflow);              }         });     }      /**      * showing popup menu when tapping on 3 dots      */     private void showpopupmenu(view view) {         // inflate menu         popupmenu popup = new popupmenu(mcontext, view);         menuinflater inflater = popup.getmenuinflater();         inflater.inflate(r.menu.menu_album, popup.getmenu());         popup.setonmenuitemclicklistener(new mymenuitemclicklistener());         popup.show();     }      /**      * click listener popup menu items      */     class mymenuitemclicklistener implements popupmenu.onmenuitemclicklistener {          public mymenuitemclicklistener() {         }          @override         public boolean onmenuitemclick(menuitem menuitem) {             switch (menuitem.getitemid()) {                 case r.id.action_add_favourite:                     toast.maketext(mcontext, "add favourite", toast.length_short).show();                     return true;                 case r.id.action_play_next:                     toast.maketext(mcontext, "play next", toast.length_short).show();                     return true;                 //------------------------------------------------------------------------------------------------                 case r.id.action_save_file:                 viewgroup parent = (viewgroup) view;                 textview = (textview) parent.findviewbyid(r.id.title);         string qq = as.gettext().tostring();          toast.maketext(mainactivity.this, qq, toast.length_short).show();          if (qq.equals("save file")){             intent i=new intent(albumadapter.this,youtube_player.class);             startactivity(i);         }                      return true;                 //--------------------------------------------------------------------------------------------                 default:             }             return false;         } 

i need code used in class..

viewgroup parent = (viewgroup) view;                 textview = (textview) parent.findviewbyid(r.id.title);         string qq = as.gettext().tostring();          toast.maketext(mainactivity.this, qq, toast.length_short).show();          if (qq.equals("save file")){             intent i=new intent(albumadapter.this,youtube_player.class);             startactivity(i);         } 

here full working demo

        button btn = (button) findviewbyid(r.id.button);         btn.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view view) {                 popupmenu popupmenu = new popupmenu(context, view);                 popupmenu.setonmenuitemclicklistener(new popupmenu.onmenuitemclicklistener() {                     @override                     public boolean onmenuitemclick(menuitem item) {                         // todo auto-generated method stub                         switch (item.getitemid()) {                             case r.id.one:                                 toast.maketext(getapplicationcontext(), "1",                                         toast.length_short).show();                                 return true;                             case r.id.two:                                 toast.maketext(getapplicationcontext(), "2",                                         toast.length_short).show();                                 return true;                             case r.id.three:                                 toast.maketext(getapplicationcontext(), "3",                                         toast.length_short).show();                                 return true;                         }                         return false;                     }                 });                 popupmenu.inflate(r.menu.main);                 popupmenu.show();             }         }); 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -