java - how to send a image to next screen on button click -



java - how to send a image to next screen on button click -

i created grid view app in swiping images on swipe_view screen.

now want send image showing on swipe_screen new screen.

what want image current on swipe_view screen want send image new screen on button click.

see code.

mainactivity.java

package com.td.gridview; import android.app.activity; import android.content.context; import android.content.intent; import android.os.bundle; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.view.viewgroup.layoutparams; import android.view.viewtreeobserver; import android.widget.adapterview; import android.widget.baseadapter; import android.widget.gridview; import android.widget.imageview; import android.widget.relativelayout; import android.widget.textview; import android.widget.adapterview.onitemclicklistener; public class mainactivity extends activity { private gridview photogrid; private int mphotosize, mphotospacing; private imageadapter imageadapter; // items add together grid private static final string[] content = new string[] { "akon", "justin bieber", "alright", "big sean", "britney spears", "hilary", "micheal buble", "akon", "justin bieber", "alright", "big sean", "britney spears", "hilary", "micheal buble", "britney spears", "hilary", "micheal buble", "akon", "justin bieber", "alright", "big sean", "britney spears", "hilary", "micheal buble", "akon", "justin bieber", "alright", "big sean", "britney spears", "hilary", "micheal buble", "akon", "justin bieber", "alright", "big sean", "britney spears", "hilary", "micheal buble", "britney spears", "hilary", "micheal buble", "akon", "justin bieber", "alright", "big sean", "britney spears", "hilary", "micheal buble" }; static final int[] icons = new int[] { r.drawable.cover_akon, r.drawable.cover_justin, r.drawable.cover_alright, r.drawable.cover_big_sean, r.drawable.cover_britney, r.drawable.cover_hilary, r.drawable.cover_mb, r.drawable.cover_akon, r.drawable.cover_justin, r.drawable.cover_alright, r.drawable.cover_big_sean, r.drawable.cover_britney, r.drawable.cover_hilary, r.drawable.cover_mb, r.drawable.cover_britney, r.drawable.cover_hilary, r.drawable.cover_mb, r.drawable.cover_akon, r.drawable.cover_justin, r.drawable.cover_alright, r.drawable.cover_big_sean, r.drawable.cover_britney, r.drawable.cover_hilary, r.drawable.cover_mb, r.drawable.cover_akon, r.drawable.cover_justin, r.drawable.cover_alright, r.drawable.cover_big_sean, r.drawable.cover_britney, r.drawable.cover_hilary, r.drawable.cover_mb, r.drawable.cover_akon, r.drawable.cover_justin, r.drawable.cover_alright, r.drawable.cover_big_sean, r.drawable.cover_britney, r.drawable.cover_hilary, r.drawable.cover_mb, r.drawable.cover_britney, r.drawable.cover_hilary, r.drawable.cover_mb, r.drawable.cover_akon, r.drawable.cover_justin, r.drawable.cover_alright, r.drawable.cover_big_sean, r.drawable.cover_britney, r.drawable.cover_hilary, r.drawable.cover_mb }; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); // photo size , spacing mphotosize = getresources().getdimensionpixelsize(r.dimen.photo_size); mphotospacing = getresources().getdimensionpixelsize(r.dimen.photo_spacing); // initialize image adapter imageadapter = new imageadapter(); photogrid = (gridview) findviewbyid(r.id.albumgrid); //start sent image total screen /** * on click event single gridview item * */ photogrid.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view v, int position, long id ) { // sending image id fullscreenactivity intent = new intent(getapplicationcontext(), swipeactivity.class); // passing array index i.putextra("id", position); startactivity(i); } }); //end sent image total screen // set image adapter gridview photogrid.setadapter(imageadapter); // view tree observer of grid , set height , numcols dynamically photogrid.getviewtreeobserver().addongloballayoutlistener(new viewtreeobserver.ongloballayoutlistener() { @override public void ongloballayout() { if (imageadapter.getnumcolumns() == 0) { final int numcolumns = (int) math.floor(photogrid.getwidth() / (mphotosize + mphotospacing)); if (numcolumns > 0) { final int columnwidth = (photogrid.getwidth() / numcolumns) - mphotospacing; imageadapter.setnumcolumns(numcolumns); imageadapter.setitemheight(columnwidth); } } } }); } // ///////// imageadapter class ///////////////// public class imageadapter extends baseadapter { private layoutinflater minflater; private int mitemheight = 0; private int mnumcolumns = 0; private relativelayout.layoutparams mimageviewlayoutparams; public imageadapter() { minflater = (layoutinflater) getsystemservice(context.layout_inflater_service); mimageviewlayoutparams = new relativelayout.layoutparams(layoutparams.match_parent, layoutparams.match_parent); } public int getcount() { homecoming content.length; } // set numcols public void setnumcolumns(int numcolumns) { mnumcolumns = numcolumns; } public int getnumcolumns() { homecoming mnumcolumns; } // set photo item height public void setitemheight(int height) { if (height == mitemheight) { return; } mitemheight = height; mimageviewlayoutparams = new relativelayout.layoutparams(layoutparams.match_parent, mitemheight); notifydatasetchanged(); } public object getitem(int position) { homecoming position; } public long getitemid(int position) { homecoming position; } public view getview(final int position, view view, viewgroup parent) { if (view == null) view = minflater.inflate(r.layout.photo_item, null); imageview cover = (imageview) view.findviewbyid(r.id.cover); textview title = (textview) view.findviewbyid(r.id.title); cover.setlayoutparams(mimageviewlayoutparams); // check height matches our calculated column width if (cover.getlayoutparams().height != mitemheight) { cover.setlayoutparams(mimageviewlayoutparams); } cover.setimageresource(icons[position % icons.length]); title.settext(content[position % content.length]); homecoming view; } } } //swipe image class

swipeactivity.java

package com.td.gridview; import android.app.activity; import android.content.context; import android.content.intent; import android.os.bundle; import android.support.v4.view.pageradapter; import android.support.v4.view.viewpager; import android.view.view; import android.view.viewgroup; import android.widget.button; import android.widget.imageview; public class swipeactivity extends activity { @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.swipe_view); // intent info intent = getintent(); // selected image id int position = i.getextras().getint("id"); viewpager viewpager = (viewpager) findviewbyid(r.id.view_pager); imagepageradapter adapter = new imagepageradapter(); viewpager.setadapter(adapter); viewpager.setcurrentitem(position); //send image full_view.xml screen on button click button b = (button)findviewbyid(r.id.xoom); b.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { // todo auto-generated method stub // how sent current showing image new screen } }); // //send info grid view on button click button b1 = (button)findviewbyid(r.id.grid); b1.setonclicklistener(new view.onclicklistener() { public void onclick(view v2) { // // todo auto-generated method stub intent i4 = new intent(getapplicationcontext(), mainactivity.class); // passing array index startactivity(i4); } }); } private class imagepageradapter extends pageradapter { int[] icons = mainactivity.icons; @override public int getcount() { homecoming icons.length; } @override public boolean isviewfromobject(view view, object object) { homecoming view == ((imageview) object); } @override public object instantiateitem(viewgroup container, int position) { context context = swipeactivity.this; imageview imageview = new imageview(context); // int padding = context.getresources().getdimensionpixelsize( // r.dimen.padding_large); // imageview.setpadding(padding, padding, padding, padding); imageview.setscaletype(imageview.scaletype.fit_center); imageview.setimageresource(icons[position]); ((viewpager) container).addview(imageview, 0); homecoming imageview; } @override public void destroyitem(viewgroup container, int position, object object) { ((viewpager) container).removeview((imageview) object); } } } //swipe image layout

swipe_view.xml

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <android.support.v4.view.viewpager xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/view_pager" android:layout_width="fill_parent" android:layout_height="fill_parent" /> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignparentbottom="true" android:orientation="horizontal" android:weightsum="3" > <button android:id="@+id/grid" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="grid" /> <button android:id="@+id/xoom" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="zoom"/> <button android:id="@+id/wll" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="wallpaper" /> </linearlayout> </relativelayout>

below class , xml want image swipe_view screen

full_zoom.java

package com.td.gridview; import android.os.bundle; import android.app.activity; public class full_zoom extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.full_view); } }

full_view.xml

<android.support.v4.view.viewpager xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/view_full" android:layout_width="fill_parent" android:layout_height="fill_parent" />

_________________________________________________________________________________

this tried after trying happens position selected grid image not swipe_view screen. want , send image swipe_view screen not selected grid image.

because want zoom current swiping image in new screen.

but because of code

// intent info intent i3 = getintent(); // selected image id int position = i3.getextras().getint("id"); // sending image id fullscreenactivity intent i2 = new intent(getapplicationcontext(), full_zoom.class); // passing array index i2.putextra(null, r.id.view_pager); startactivity(i2);

it image selected grid view want image current showing swiping image.

swipeactivity.java

//send image full_view.xml screen on button click button b = (button)findviewbyid(r.id.xoom); b.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { // // todo auto-generated method stub // intent info intent i3 = getintent(); // selected image id int position = i3.getextras().getint("id"); // sending image id fullscreenactivity intent i2 = new intent(getapplicationcontext(), full_zoom.class); // passing array index i2.putextra(null, r.id.view_pager); startactivity(i2); } }); //

full_zoom.java(new screen class)

public class full_zoom extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.full_view); // intent info intent = getintent(); // selected image id int position = i.getextras().getint("id"); viewpager viewpager = (viewpager) findviewbyid(r.id.view_pager); pinchzoom img = new pinchzoom(this); img.setimageresource(mainactivity.icons[r.id.view_pager]); img.setmaxzoom(4f); setcontentview(img); } }

send image within onclick:

intent = new intent(this,yourclassname.class); i.putextra("imageid", icons[position]); startactivity(i);

get on new activity :

bundle bd = getintent().getextras(); int imageres = bd.getint("imageid"); imageview image = (imageview) findviewbyid(r.id.imageview); image.setimageresource(imageres);

java android xml navigation buttonclick

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -