android - Set String Array to ImageView -
i want set string array contain images position imageview. string array passed activity activity b , set imageview in activity b. how should set? below codes :
from activity :
string[] outputstrarr = new string[selecteditems.size()]; (int = 0; < selecteditems.size(); i++) { outputstrarr[i] = selecteditems.get(i); //log.i(galleryactivity.tag,outputstrarr[i]); } intent intent = new intent(getapplicationcontext(), mainactivity.class); // create bundle object bundle bundle = new bundle(); bundle.putstringarray("griditem", outputstrarr); // add bundle intent. intent.putextras(bundle); // start mainactivity startactivity(intent);
from activity b:
public void onresume() { super.onresume(); bundle bundle = getintent().getextras(); if (bundle != null){ string[] result = bundle.getstringarray("griditem"); if(result != null){; // want set string array imageview here. } } }
thanks !
first image needs included inside drawable folder, here can do:
resources res = getresources(); string mdrawablename = result.get(position);; int resid = res.getidentifier(mdrawablename , "drawable", getpackagename()); drawable drawable = res.getdrawable(resid ); imageview.setimagedrawable(drawable );
this should work perfectly. let me know if have issue.
edit:
try below code set bitmap images file stored inside sd-card:
file imgfile = new file("/sdcard/images/my_image.jpg"); if(imgfile.exists()){ bitmap mybitmap = bitmapfactory.decodefile(imgfile.getabsolutepath()); imageview myimage = (imageview) findviewbyid(r.id.imageviewtest); myimage.setimagebitmap(mybitmap); }
and include permission in manifest file:
<uses-permission android:name="android.permission.write_external_storage" />
Comments
Post a Comment