java - Putting OnRatingBarChangeListener in Universal-Image-Loader in GridView Implementation -
the main purpose of question know put onratingbarchangelistener in uil. below each image added ratingbars(which working), next thing should listen users action towards ratingbar's selection. great appreciated.
public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.ac_image_grid); bundle bundle = getintent().getextras(); imageurls = bundle.getstringarray(extra.images); options = new displayimageoptions.builder() .showstubimage(r.drawable.ic_stub) .showimageforemptyuri(r.drawable.ic_empty) .showimageonfail(r.drawable.ic_error) .cacheinmemory(true) .cacheondisc(true) .bitmapconfig(bitmap.config.rgb_565) .build(); listview = (gridview) findviewbyid(r.id.gridview); rbar = (ratingbar)findviewbyid(r.id.ratingbar1); ((gridview) listview).setadapter(new imageadapter()); listview.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { startimagepageractivity(position); toast.maketext(getbasecontext(), "clieckeed",toast.length_short).show(); log.d("inside onclick:", view.tostring()); } }); rbar.setonratingbarchangelistener(new onratingbarchangelistener() { @override public void onratingchanged(ratingbar ratingbar, float rating, boolean fromuser) { toast.maketext(getbasecontext(), "rating:"+rating, toast.length_short).show(); }}); }
populating view:
public view getview(final int position, view convertview, viewgroup parent) { view view = convertview; final viewholder holder; if (convertview == null) { view = getlayoutinflater().inflate(r.layout.item_grid_image, parent, false); holder = new viewholder(); holder.text = (textview) view.findviewbyid(r.id.text1); holder.image = (imageview) view.findviewbyid(r.id.imageview1); holder.br = (ratingbar) view.findviewbyid(r.id.ratingbar1); view.settag(holder); } else { holder = (viewholder) view.gettag(); } holder.text.settext("naaa na"); holder.br.setstepsize(1); holder.br.setfocusable(false); log.d("image path value in gridview: ", imageurls[position].tostring()); imageloader.displayimage(imageurls[position], holder.image, options); return view; }
log cat:
07-11 09:41:16.783: e/androidruntime(31846): fatal exception: main 07-11 09:41:16.783: e/androidruntime(31846): java.lang.runtimeexception: unable start activity componentinfo{com.jinisys.restoplusordering/com.restoplus.galleryuil.imagegridactivity}: java.lang.nullpointerexception 07-11 09:41:16.783: e/androidruntime(31846): @ android.app.activitythread.performlaunchactivity(activitythread.java:2059) 07-11 09:41:16.783: e/androidruntime(31846): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2084) 07-11 09:41:16.783: e/androidruntime(31846): @ android.app.activitythread.access$600(activitythread.java:130) 07-11 09:41:16.783: e/androidruntime(31846): @ android.app.activitythread$h.handlemessage(activitythread.java:1195) 07-11 09:41:16.783: e/androidruntime(31846): @ android.os.looper.loop(looper.java:137) 07-11 09:41:16.783: e/androidruntime(31846): @ java.lang.reflect.method.invokenative(native method) 07-11 09:41:16.783: e/androidruntime(31846): @ java.lang.reflect.method.invoke(method.java:511) 07-11 09:41:16.783: e/androidruntime(31846): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:553) 07-11 09:41:16.783: e/androidruntime(31846): @ dalvik.system.nativestart.main(native method) 07-11 09:41:16.783: e/androidruntime(31846): caused by: java.lang.nullpointerexception 07-11 09:41:16.783: e/androidruntime(31846): @ com.restoplus.galleryuil.imagegridactivity.oncreate(imagegridactivity.java:70) 07-11 09:41:16.783: e/androidruntime(31846): @ android.app.activity.performcreate(activity.java:5008) 07-11 09:41:16.783: e/androidruntime(31846): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1079) 07-11 09:41:16.783: e/androidruntime(31846): @ android.app.activitythread.performlaunchactivity(activitythread.java:2023) 07-11 09:41:16.783: e/androidruntime(31846): ... 11 more
the line 70, code rbar.setonratingbarchangelistener(new onratingbarchangelistener()
since need put listener in ratingbar have put setonratingbarchangelistener
inside getview()
holder.br.setonratingbarchangelistener(new onratingbarchangelistener() { public void onratingchanged(ratingbar ratingbar, float rating, boolean fromuser) { } });
Comments
Post a Comment