java - How to display image on full screen on click android? -
i newbie in android programming , created image gallery app display images on sd card in grid view . it's working fine want select image , display on full screen in activity. guess easier when using string array using array list hold/store images. don't know how display images on full screen using that. can me out?
imagegallery.java
public class imagegallery extends appcompatactivity { public static arraylist<model_images> al_images = new arraylist<>(); boolean boolean_folder; adapter_photosfolder obj_adapter; gridview gv_folder; private static final int request_permissions = 100; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_image_gallery); gv_folder = (gridview)findviewbyid(r.id.gv_folder); gv_folder.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> adapterview, view view, int i, long l) { intent intent = new intent(getapplicationcontext(), photosactivity.class); intent.putextra("value",i); startactivity(intent); } }); public arraylist<model_images> fn_imagespath() { al_images.clear(); int int_position = 0; uri uri; cursor cursor; int column_index_data, column_index_folder_name; string absolutepathofimage; uri = mediastore.images.media.external_content_uri; string[] projection = {mediastore.mediacolumns.data, mediastore.images.media.bucket_display_name}; final string orderby = mediastore.images.media.date_taken; cursor = getapplicationcontext().getcontentresolver().query(uri, projection, null, null, orderby + " desc"); column_index_data = cursor.getcolumnindexorthrow(mediastore.mediacolumns.data); column_index_folder_name = cursor.getcolumnindexorthrow(mediastore.images.media.bucket_display_name); while (cursor.movetonext()) { absolutepathofimage = cursor.getstring(column_index_data); log.e("column", absolutepathofimage); log.e("folder", cursor.getstring(column_index_folder_name)); (int = 0; < al_images.size(); i++) { if (al_images.get(i).getstr_folder().equals(cursor.getstring(column_index_folder_name))) { boolean_folder = true; int_position = i; break; } else { boolean_folder = false; } } if (boolean_folder) { arraylist<string> al_path = new arraylist<>(); al_path.addall(al_images.get(int_position).getal_imagepath()); al_path.add(absolutepathofimage); al_images.get(int_position).setal_imagepath(al_path); } else { arraylist<string> al_path = new arraylist<>(); al_path.add(absolutepathofimage); model_images obj_model = new model_images(); obj_model.setstr_folder(cursor.getstring(column_index_folder_name)); obj_model.setal_imagepath(al_path); al_images.add(obj_model); } } (int = 0; < al_images.size(); i++) { log.e("folder", al_images.get(i).getstr_folder()); (int j = 0; j < al_images.get(i).getal_imagepath().size(); j++) { log.e("file", al_images.get(i).getal_imagepath().get(j)); } } obj_adapter = new adapter_photosfolder(getapplicationcontext(),al_images); gv_folder.setadapter(obj_adapter); return al_images; }
photosactivity.java
public class photosactivity extends appcompatactivity { int int_position; private gridview gridview; gridviewadapter adapter; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_image_gallery); gridview = (gridview)findviewbyid(r.id.gv_folder); int_position = getintent().getintextra("value", 0); adapter = new gridviewadapter(this, al_images,int_position); gridview.setadapter(adapter); final imageview imageview = (imageview) findviewbyid(r.id.iv_image); gridview.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { intent = new intent(getapplicationcontext(), fullimageactivity.class); i.putextra("id", position); startactivity(i); } }); }
gridviewadapter.java
public class gridviewadapter extends arrayadapter<model_images> { context context; viewholder viewholder; arraylist<model_images> al_menu = new arraylist<>(); int int_position; public gridviewadapter(context context, arraylist<model_images> al_menu,int int_position) { super(context, r.layout.activity_adapter__photos_folder, al_menu); this.al_menu = al_menu; this.context = context; this.int_position = int_position; } @override public int getcount() { log.e("adapter list size", al_menu.get(int_position).getal_imagepath().size() + ""); return al_menu.get(int_position).getal_imagepath().size(); } @override public int getitemviewtype(int position) { return position; } @override public int getviewtypecount() { if (al_menu.get(int_position).getal_imagepath().size() > 0) { return al_menu.get(int_position).getal_imagepath().size(); } else { return 1; } } @override public long getitemid(int position) { return position; } @override public view getview(final int position, view convertview, viewgroup parent) { if (convertview == null) { viewholder = new viewholder(); convertview = layoutinflater.from(getcontext()).inflate(r.layout.activity_adapter__photos_folder, parent, false); viewholder.tv_foldern = (textview) convertview.findviewbyid(r.id.tv_folder); viewholder.tv_foldersize = (textview) convertview.findviewbyid(r.id.tv_folder2); viewholder.iv_image = (imageview) convertview.findviewbyid(r.id.iv_image); convertview.settag(viewholder); } else { viewholder = (viewholder) convertview.gettag(); } viewholder.tv_foldern.setvisibility(view.gone); viewholder.tv_foldersize.setvisibility(view.gone); glide.with(context).load("file://" + al_menu.get(int_position).getal_imagepath().get(position)) .diskcachestrategy(diskcachestrategy.none) .skipmemorycache(true) .into(viewholder.iv_image); return convertview; } private static class viewholder { textview tv_foldern, tv_foldersize; imageview iv_image; } }
fullimageactivity.java
public class fullimageactivity extends appcompatactivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_full_image); intent = getintent(); // selected image id int position1 = i.getextras().getint("id"); imageview imageview = (imageview) findviewbyid(r.id.fullimage); imageview.setimageresource(); } }
pass image path second activity, in case "file://" + al_images.get(int_position).getal_imagepath().get(position)
.
then second activity, can display using glide
glide.with(context).load(path) .into(imageview);
Comments
Post a Comment