android - Clicking the button of listview is not fetching the corresponding textview value of that listview item -


im having buttons each items of listview. when button clicked, has fetch value of corresponding listview item.

following getview method.

@override     public view getview(int position, view convertview, viewgroup parent) {          view = convertview;          if (convertview == null) {             //inflate view each row of listview             if (imageloader == null)                 imageloader = appcontroller.getinstance().getimageloader();             view = inflator.inflate(r.layout.pending_orders_fragment, null);             vholder = new viewholder();             vholder.mshippngrefno = (textview) view.findviewbyid(r.id.shipment_ref_no_value);             vholder.contact = (imagebutton) view.findviewbyid(r.id.imagebutton);             vholder.mshippingstatus.settag(position);              view.settag(vholder);         } else             vholder = (viewholder) view.gettag();          pendingordersdao item = listforview.get(position);           vholder.mshippngrefno.settext(item.getsipmentno());         vholder.contact.setonclicklistener(this.onclicklistener);          return view;     }      public void setonbuttonclicklistener(final view.onclicklistener onclicklistener) {         this.onclicklistener = onclicklistener;     } 

im invoking button follows in code..

adapter.setonbuttonclicklistener(new view.onclicklistener() {                                         @override                                         public void onclick(view v) {                                             linearlayout relativelayout = (linearlayout) v.getparent();                                             textview textview = (textview) relativelayout.findviewbyid(r.id.shipment_ref_no_value);                                             toast.maketext(getactivity(),textview.gettext().tostring(),toast.length_short).show();                                          }                                     }); 

but im getting null pointer exception while doing so.how can sort out?

following logcat

java.lang.nullpointerexception @ com.vaighai.fragments.myordersfragment$2$1.onclick(myordersfragment.java:253) @ android.view.view.performclick(view.java:4475) @ android.view.view$performclick.run(view.java:18786) @ android.os.handler.handlecallback(handler.java:730) @ android.os.handler.dispatchmessage(handler.java:92) @ android.os.looper.loop(looper.java:176)

updated logcat:

fatal exception: main java.lang.nullpointerexception @

com.vaighai.adapters.customadapter$1.onclick(customadapter.java:122) @ android.view.view.performclick(view.java:4475) @ android.view.view$performclick.run(view.java:18786) @ android.os.handler.handlecallback(handler.java:730) @ android.os.handler.dispatchmessage(handler.java:92) @ android.os.looper.loop(looper.java:176) @ android.app.activitythread.main(activitythread.java:5419) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:525) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1046) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:862) @ dalvik.system.nativestart.main(native method)

you can directly set setonclicklistener .so remove code

vholder.contact.setonclicklistener(this.onclicklistener); 

add following code

    vholder.contact.setonclicklistener(new onclicklistener() {     public void onclick(view v) {         linearlayout relativelayout = (linearlayout) v.getparent();         textview textview = (textview) relativelayout.findviewbyid(r.id.shipment_ref_no_value);         toast.maketext(context,textview.gettext().tostring(),toast.length_short).show();}        }); 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -