Calling a method inside listview item click in android -
Calling a method inside listview item click in android -
i need phone call method within item click of listview. app stops responding when running. i'm trying run method called getsubvitals within class getsubvitals(another class). how phone call such method? help appreciated.
public class vitallistactivity extends actionbaractivity { getsubvitals getsub; fragmentmanager fm = getsupportfragmentmanager(); public static list<string> vitallist = new arraylist<>(); @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_vital_list); intent intent = getintent(); string status = intent.getstringextra(loginactivity.extra_message); if(status.equals("true")){ new getparentvitalname().execute(); //log.d("check list",vitallist.get(0)); log.d("tag", "execute complete"); //populatelistview(); log.d("tag", "populate complete"); } } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.menu_vital_list, menu); homecoming true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); //noinspection simplifiableifstatement if (id == r.id.action_settings) { homecoming true; } homecoming super.onoptionsitemselected(item); } private void populatelistview(list<string> vitallist) { arrayadapter<string> adapter = new mylistadapter(vitallist); listview list = (listview) findviewbyid(r.id.vitalslistview); list.setadapter(adapter); } private class mylistadapter extends arrayadapter<string>{ public mylistadapter(list<string> vitallist){ super(vitallistactivity.this, r.layout.vital_list_layout, vitallist); log.d("tag", "super okay"); } @override public view getview(int position, view convertview, viewgroup parent) { //return super.getview(position, convertview, parent); //making sure we've view work with(may have been given null log.d("tag","inside view"); view itemview = convertview; if (itemview == null) itemview = getlayoutinflater().inflate(r.layout.vital_list_layout, parent, false); string currentvital = vitallist.get(position); //fill view textview vitaltext = (textview) itemview.findviewbyid((r.id.vitaltextview)); vitaltext.settext(currentvital); homecoming itemview; } @override public int getcount() { // todo auto-generated method stub homecoming vitallist.size(); } } private class getparentvitalname extends asynctask<string, string, string> { protected string doinbackground(string... params){ string responsetext = null; httpclient httpclient = servicehelper.gethttpclient(); httpcontext localcontext = new basichttpcontext(); httpget httpget = new httpget("http://test.gogch.com/gch-restful/vitals/custome/added/parentvitals"); log.d("kmn", "sucess"); seek { httpresponse response = httpclient.execute(httpget); log.d("dfgh","success again."); int statuscode = response.getstatusline().getstatuscode(); log.d("http post response v", integer.tostring(statuscode)); responsetext = entityutils.tostring(response.getentity()); log.d("http post response v", responsetext); } catch(clientprotocolexception e){ e.printstacktrace(); } grab (ioexception e){ e.printstacktrace(); } homecoming responsetext; } protected void onpostexecute(string responsetext){ if (responsetext != null){ seek { jsonarray vitalsarray = new jsonarray(responsetext); for(int =0;i<vitalsarray.length();i++){ jsonobject vitalsobject = vitalsarray.getjsonobject(i); string parentvitalname = vitalsobject.getstring("parentvitalname"); vitallist.add(parentvitalname); log.d("ygvj",vitallist.get(i)); } populatelistview(vitallist); registerlistclick(); } grab (jsonexception e){ e.printstacktrace(); } } } } private void registerlistclick(){ listview list = (listview) findviewbyid(r.id.vitalslistview); list.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view viewclicked, int position, long id) { string vitalname = vitallist.get(position); jsonarray subvitalsarray = null; log.d("hgfd","sadsadsad"); string responsetext = getsub.getsubvitals(vitalname); log.d("hgfd",responsetext); if (responsetext != null) { seek { jsonarray vitalsarray = new jsonarray(responsetext); (int = 0; < vitalsarray.length(); i++) { jsonobject vitalsobject = vitalsarray.getjsonobject(i); string parentvitalname = vitalsobject.getstring("parentvitalname"); if (parentvitalname.equals(vitalname)) { subvitalsarray = vitalsobject.getjsonarray("subvitals"); } } } grab (jsonexception e) { e.printstacktrace(); } } arraylist<subvitals> subvitallist = new arraylist<subvitals>(); for(int =0; i<subvitalsarray.length();i++){ seek { //map.clear(); jsonobject obj = subvitalsarray.getjsonobject(i); string unit = obj.getstring("unit"); string subvitalid = obj.getstring("subvitalid"); string subvitalname = obj.getstring("subvitalname"); string unitid = obj.getstring("unitid"); subvitals subvitals = new subvitals(); subvitals.setunit(unit); subvitals.setsubvitalid(subvitalid); subvitals.setsubvitalname(subvitalname); subvitals.setunitid(unitid); //map.put("unit",unit); //map.put("subvitalid",subvitalid); //map.put("subvitalname", subvitalname); //map.put("unitid", unitid); subvitallist.add(subvitals); } catch(jsonexception e){ e.printstacktrace(); } } //dfragment dfragment = dfragment.newinstance(subvitallist); // show dialogfragment //dfragment.show(fm, "dialog"); //string message = "you clicked" + vitalname; //toast.maketext(vitallistactivity.this,message,toast.length_long).show(); } }); } }
this logcat says:
04-07 18:31:46.759 29734-29734/com.cinch.getvitalsapp e/androidruntime﹕ fatal exception: main process: com.cinch.getvitalsapp, pid: 29734 java.lang.nullpointerexception: effort invoke virtual method 'java.lang.string com.cinch.getvitalsapp.tasks.getsubvitals.getsubvitals(java.lang.string)' on null object reference @ com.cinch.getvitalsapp.activities.vitallistactivity$1.onitemclick(vitallistactivity.java:186)
according error output getsub variable null ....
--> either create getsubvitals method static or initialize getsub
android
Comments
Post a Comment