ImageView click event in Android -
i have images under gallery. when launch application loads gallery
bottom of screen. after, click particular image gallery image display in center of screen large size. after click large size image need display suitable images large size images.
code:
<gallery android:id="@+id/gallery1" android:layout_margintop="100dp" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <imageview android:id="@+id/image1" android:layout_width="200dp" android:layout_height="200dp" android:layout_margintop="70dp" android:scaletype="matrix" />
images:
integer[] imageids = { r.drawable.img, r.drawable.img1, r.drawable.img2, r.drawable.img3, r.drawable.img4, r.drawable.img5, r.drawable.img6, r.drawable.img7 }; integer[] imageids1 = { r.drawable.nat, r.drawable.nat1, r.drawable.nat2, r.drawable.nat3, r.drawable.nat4, r.drawable.nat5, r.drawable.nat6, r.drawable.nat7 }; public class imageadapter extends baseadapter { context context; int itembackground; public imageadapter(context c) { context = c; //---setting style--- // typedarray = obtainstyledattributes(r.styleable.gallery1); // itembackground = a.getresourceid( // r.styleable.gallery1_android_galleryitembackground, 0); // a.recycle(); } //---returns number of images--- public int getcount() { return imageids.length; } //---returns item--- public object getitem(int position) { return position; } //--returns id of item--- public long getitemid(int position) { return position; } //---returns imageview view--- @override public view getview(int position, view convertview, viewgroup parent) { // todo auto-generated method stub imageview imageview; if (convertview == null) { imageview = new imageview(context); //set imageview display image in array // @ user selected position imageview.setimageresource(imageids[position]); imageview.setscaletype(imageview.scaletype.fit_xy); imageview.setlayoutparams(new gallery.layoutparams(150, 120)); // imageview.setlayoutparams(new gallery.layoutparams(300, 300)); } else { imageview = (imageview) convertview; } imageview.setbackgroundresource(itembackground); return imageview; } }
gallery click:
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_onclick); gallery gallery=(gallery)findviewbyid(r.id.gallery1); gallery.setadapter(new imageadapter(mainactivity.this)); gallery.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view v, int position, long id) { // todo auto-generated method stub final imageview imageview = (imageview) findviewbyid(r.id.image1); imageview.setimageresource(imageids[position]); } }
here, when click imageview (imageids[position])
need display imageids1[position]
separate images
i tried click imageview (imageids[position]) :
imageview.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view v, int position, long id) { // todo auto-generated method stub final imageview imageview1 = (imageview) findviewbyid(r.id.image2); imageview1.setimageresource(imageids1[position]); }
but it's not working. need set onitemclick event imageview display imageids1[position] images
Comments
Post a Comment