i'm using surfaceview in 1st activity. on clicking image using surfaceview, move 2nd activity storing path of clicked image. in 2nd activity, want display image in gallery.
in 2nd activity on button click, again move 1st activity , after clicking picture, move 2nd activity.
now in 2nd activity, there 2 images should displayed in gallery.
my problem after clicking 1st image, gallery not displaying anything. note getview() of adapter set gallery getting called.
but after clicking 2nd image onwards, when there 2 or more images in gallery, getting displayed.
i tried g.refreshdrawablestate(); after
g.setadapter(new imageadapter(this)); g.setonitemclicklistener(this); g.setselection(0, false); but no avail.
i know have written here sounds complex, try visualize scenario.
any appreciated.
edit
imageadapter.java
public class imageadapter extends baseadapter { public imageadapter(context c) { mcontext = c; } public int getcount() { return mimageids.length;//mimageids array of image paths } public object getitem(int position) { return position; } public long getitemid(int position) { return position; } public view getview(int position, view convertview, viewgroup parent) { imageview = new imageview(mcontext); final string imageuri = mimageids[position].trim(); try { if (imageuri.length() != 0) { file f = new file(imageuri); if (f.exists()) { b = constants.shrinkbitmap(f.getpath(), 800, 800); d = new bitmapdrawable(getresources(), b); i.setimagedrawable(d); } else { i.setbackgroundcolor(color.white); i.setimageresource(r.drawable.ic_launcher); } } else { i.setbackgroundresource(r.drawable.ic_launcher); } } catch (exception e) { e.printstacktrace(); } i.setadjustviewbounds(true); //below "length" predefined value i.setpadding(math.round(length * 0.05f), 0, math.round(length * 0.05f), 0); i.setlayoutparams(new gallery.layoutparams(math .round(length * 0.9f), layoutparams.wrap_content)); i.setscaletype(scaletype.fit_xy); return i; } } edit (2)
after vikram's suggestion, tried logging length value , indeed 0 first time i.e. when calling i.setlayoutparams(new gallery.layoutparams(math.round(length * 0.9f),layoutparams.wrap_content));
i set length variable after oncreate() way:
g.post(new runnable() { public void run() { length = g.getright() - g.getleft(); } }); as want retrieve width of parent layout in code , accordingly set gallery item width.
i know reason length 0 setcontentview() takes bit of time take effect. how can retrieve before adapter called?
the variable length seems problem here. if it's value zero, when getview() first item called, width parameter set zero.
in edit, length indeed getting non-zero value, perhaps bit late. can make following call update view:
myadapter.notifydatasetchanged(); this call should placed inside run() after computation of length.
your workaround 'blinking' fine. alternative(and if gallery's width should match screen width), try this:
in place of:
g.post(new runnable() { public void run() { length = g.getright() - g.getleft(); } }); put:
point pointsize = new point(); getwindowmanager().getdefaultdisplay().getsize(pointsize); length = pointsize.x; place before initializing adapter.
another thing note here g.getright() computed as:
g.getright() = g.getleft() + g.getwidth() so, compute length, may do:
length = g.getwidth() as:
getwidth() = getright() - getleft()
Comments
Post a Comment