android - How can i make my bitmap passed to another activity be visible? -
i have 2 activities own gridviews , adapters , want pass data(containg both image (in form of bitmap resources)and text) 1 activity other. problem having image. not display on gridview text , when try add data, overwrites former one. please can tell me doing wrong or need do? (i want application function when adding favourite online radio station preset list). below acitivies (cropped)
first activity
com_res=getresources(); comm_appslist=new arraylist<appis_infos>(); comm_appslist.add(new appis_infos(bitmapfactory.decoderesource(com_res, r.drawable.skype), "skype","com.skype.raider")); comm_appslist.add(new appis_infos(bitmapfactory.decoderesource(com_res, r.drawable.yahoomessenger),"messenger","com.yahoo.mobile.client.android.im")); public boolean oncontextitemselected(menuitem item) { // todo auto-generated method stub adapterview.adaptercontextmenuinfo info = (adapterview.adaptercontextmenuinfo)item.getmenuinfo(); int menuitemindex = item.getitemid(); string[] menuitems = getresources().getstringarray(r.array.menu); string menuitemname = menuitems[menuitemindex]; int menuappname=info.position; appis_infos appname = comm_appslist.get(menuappname); bitmap itemb=appname.geticon();//this need image other class when use in bitmapfactory error bitmap bmp = bitmapfactory.decoderesource(com_res, menuitemindex); intent favlist=new intent(this.getapplicationcontext(),favouritelistappis.class); bundle bbundle=new bundle(); bbundle.putparcelable("keyb", bmp); favlist.putextra("keyname", appname.getname()); startactivity(favlist); toast.maketext(getapplicationcontext(), appname.getname()+" has been added favourite list "+menuitemindex, toast.length_long).show(); return true; } class commappis_adapter extends baseadapter{ private context aicontext; private list<appis_infos>adlist; commappis_adapter(context aicontext, list<appis_infos> adlist){ aicontext=aicontext; adlist=adlist; } @override public int getcount() { // todo auto-generated method stub return adlist.size(); } @override public object getitem(int it_position) { // todo auto-generated method stub return adlist.get(it_position); } @override public long getitemid(int id_position) { // todo auto-generated method stub return id_position; } @override public view getview(int vposition, view aview, viewgroup vparent) { // todo auto-generated method stub appis_infos appsdata=adlist.get(vposition); comm_viewholder holder=null; if(aview==null){ layoutinflater apps_inflater=layoutinflater.from(aicontext); aview=apps_inflater.inflate(r.layout.comm_appis, null); holder=new comm_viewholder(); holder.apps_icons=(imageview)aview.findviewbyid(r.id.comm_imageview); holder.apps_name=(textview)aview.findviewbyid(r.id.comm_tvname); aview.settag(holder); }else{ holder=(comm_viewholder)aview.gettag(); } holder.apps_icons.setimagebitmap(appsdata.geticon()); holder.apps_name.settext(appsdata.getname()); return aview; } } class comm_viewholder{ imageview apps_icons; textview apps_name; }
the second activity
fav_gridview=(gridview)findviewbyid(r.id.gvfavist); resources fav_res=getresources(); if(getintent().getextras()!=null) { bundle bundle = this.getintent().getextras(); bmp = bundle.getparcelable("keyb"); favapp=getintent().getextras().getstring("keyname"); } fav_appslist=new arraylist<appis_infos>(); fav_appslist.add(new appis_infos( bmp, favapp,"com.skype.raider")); class favappis_adapter extends baseadapter{ private context aicontext; private list<appis_infos>adlist; favappis_adapter(context aicontext, list<appis_infos> adlist){ aicontext=aicontext; adlist=adlist; } @override public int getcount() { // todo auto-generated method stub return adlist.size(); } @override public object getitem(int it_position) { // todo auto-generated method stub return adlist.get(it_position); } @override public long getitemid(int id_position) { // todo auto-generated method stub return id_position; } @override public view getview(int vposition, view aview, viewgroup vparent) { // todo auto-generated method stub appis_infos appsdata=adlist.get(vposition); fav_viewholder holder=null; if(aview==null){ layoutinflater apps_inflater=layoutinflater.from(aicontext); aview=apps_inflater.inflate(r.layout.favlist_appis, null); holder=new fav_viewholder(); holder.apps_icons= (imageview)aview.findviewbyid(r.id.favlistimageview); holder.apps_name=(textview)aview.findviewbyid(r.id.favlisttvname); aview.settag(holder); }else{ holder=(fav_viewholder)aview.gettag(); } holder.apps_icons.setimagebitmap(appsdata.geticon()); holder.apps_name.settext(appsdata.getname()); return aview; } } class fav_viewholder{ imageview apps_icons; textview apps_name; }
their common class
public class appis_infos { private bitmap aicon; private string aname; private string packname; public appis_infos(bitmap icon, string name, string pname){ aicon=icon; aname=name; packname=pname; } public void seticon(bitmap icon){ aicon=icon; } public bitmap geticon(){ return aicon; } public void setname(string name){ aname=name; } public string getname(){ return aname; } public void setpname(string pname){ packname=pname; } public string getpname(){ return packname; } }
you can name bitmap static first.
then create method like
public static bitmap getbitmap(){ return bitmap; }
then can call other activities, bitmapwantedclass.getbitmap();
hope helps
Comments
Post a Comment