json - android from activity to fragment -
i'm new android. want set 1 of activity under 1 of tab of app(the tab fragment) when paste code fragment, there's lot of error...
there's error in new jsonparse().execute(); shows type jsonparse not visible.
in line private class jsonparse extends asynctask there's error showing illegal modifier class jsonparse.only public, abstract , final permitted.
this line pdialog = new progressdialog(tabactivityqueue.this); shows constructor progressdialog undefined.
all variables phonenumber, peoplenumber , remarks, status, table2, url not resolved variables.
what should change? i'm stuck.
here's activity code :
public class mainactivity extends activity { listview list; textview number; textview info; textview remark; textview statuss; button btngetdata; arraylist<hashmap<string, string>> oslist = new arraylist<hashmap<string, string>>(); //url json array private static string url = "http://172.22.85.235:8080/qproject/servlet/qaction?action_flag=find"; //json node names private static final string table2 = "table2"; private static final string phonenumber = "phonenumber"; private static final string peoplenumber = "peoplenumber"; private static final string remarks = "remarks"; private static final string status = "status"; jsonarray table2 = null; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); oslist = new arraylist<hashmap<string, string>>(); btngetdata = (button)findviewbyid(r.id.getdata); btngetdata.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { new jsonparse().execute(); } }); } private class jsonparse extends asynctask<string, string, jsonobject> { private progressdialog pdialog; @override protected void onpreexecute() { super.onpreexecute(); number = (textview)findviewbyid(r.id.number); info = (textview)findviewbyid(r.id.info); remark = (textview)findviewbyid(r.id.remark); statuss = (textview)findviewbyid(r.id.statuss); pdialog = new progressdialog(mainactivity.this); pdialog.setmessage("getting info ..."); pdialog.setindeterminate(false); pdialog.setcancelable(true); pdialog.show(); } @override protected jsonobject doinbackground(string... args) { jsonparser jparser = new jsonparser(); // getting json url jsonobject json = jparser.getjsonfromurl(url); homecoming json; } @override protected void onpostexecute(jsonobject json) { pdialog.dismiss(); seek { // getting json array url table2 = json.getjsonarray(table2); for(int = 0; < table2.length(); i++){ jsonobject c = table2.getjsonobject(i); // storing json item in variable string number = c.getstring(phonenumber); string info = c.getstring(peoplenumber); string remark = c.getstring(remarks); string statuss = c.getstring(status); // adding value hashmap key => value hashmap<string, string> map = new hashmap<string, string>(); map.put(phonenumber, number); map.put(peoplenumber, info); map.put(remarks, remark); map.put(status, statuss); oslist.add(map); list=(listview)findviewbyid(r.id.list); listadapter adapter = new simpleadapter(mainactivity.this, oslist, r.layout.list_item, new string[] { phonenumber,peoplenumber, remarks,status }, new int[] { r.id.number,r.id.info, r.id.remark,r.id.statuss}); list.setadapter(adapter); list.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { toast.maketext(mainactivity.this, "you clicked @ "+oslist.get(+position).get("name"), toast.length_short).show(); } }); } } grab (jsonexception e) { e.printstacktrace(); } } }
here's fragment pasted activity code in :
public class tabactivityqueue extends fragment { listview list; textview number; textview info; textview remark; textview statuss; button btngetdata; arraylist<hashmap<string, string>> oslist = new arraylist<hashmap<string, string>>(); //url json array public static string url = "http://172.22.85.235:8080/qproject/servlet/qaction?action_flag=find"; //json node names public static final string table2 = "table2"; public static final string phonenumber = "phonenumber"; public static final string peoplenumber = "peoplenumber"; public static final string remarks = "remarks"; public static final string status = "status"; jsonarray table2 = null; public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { // inflate layout fragment //this layout contains list view view view = inflater.inflate(r.layout.activity_tab_activity_queue, container, false); oslist = new arraylist<hashmap<string, string>>(); number = (textview)view.findviewbyid(r.id.number); info = (textview)view.findviewbyid(r.id.info); remark = (textview)view.findviewbyid(r.id.remark); statuss = (textview)view.findviewbyid(r.id.statuss); btngetdata = (button)view.findviewbyid(r.id.getdata); btngetdata.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { new jsonparse().execute(); } }); homecoming view; } } private class jsonparse extends asynctask<string, string, jsonobject> { private progressdialog pdialog; @override protected void onpreexecute() { super.onpreexecute(); pdialog = new progressdialog(tabactivityqueue.this); pdialog.setmessage("getting info ..."); pdialog.setindeterminate(false); pdialog.setcancelable(true); pdialog.show(); } @override protected jsonobject doinbackground(string... args) { jsonparser jparser = new jsonparser(); // getting json url jsonobject json = jparser.getjsonfromurl(url); homecoming json; } @override protected void onpostexecute(jsonobject json) { pdialog.dismiss(); seek { // getting json array url table2 = json.getjsonarray(table2); for(int = 0; < table2.length(); i++){ jsonobject c = table2.getjsonobject(i); // storing json item in variable string number = c.getstring(phonenumber); string info = c.getstring(peoplenumber); string remark = c.getstring(remarks); string statuss = c.getstring(status); // adding value hashmap key => value hashmap<string, string> map = new hashmap<string, string>(); map.put(phonenumber, number); map.put(peoplenumber, info); map.put(remarks, remark); map.put(status, statuss); oslist.add(map); list=(listview)findviewbyid(r.id.list); listadapter adapter = new simpleadapter(mainactivity.this, oslist, r.layout.list_item, new string[] { phonenumber,peoplenumber, remarks,status }, new int[] { r.id.number,r.id.info, r.id.remark,r.id.statuss}); list.setadapter(adapter); list.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { toast.maketext(mainactivity.this, "you clicked @ "+oslist.get(+position).get("name"), toast.length_short).show(); } }); } } grab (jsonexception e) { e.printstacktrace(); } } }
public class tabactivityqueue extends fragment { listview list; textview number; textview info; textview remark; textview statuss; button btngetdata; arraylist<hashmap<string, string>> oslist = new arraylist<hashmap<string, string>>(); // url json array public static string url = "http://172.22.85.235:8080/qproject/servlet/qaction?action_flag=find"; // json node names public static final string table2 = "table2"; public static final string phonenumber = "phonenumber"; public static final string peoplenumber = "peoplenumber"; public static final string remarks = "remarks"; public static final string status = "status"; jsonarray table2 = null; private activity activity; public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { // inflate layout fragment // layout contains list view view view = inflater.inflate(r.layout.activity_tab_activity_queue, container, false); oslist = new arraylist<hashmap<string, string>>(); number = (textview) view.findviewbyid(r.id.number); info = (textview) view.findviewbyid(r.id.info); remark = (textview) view.findviewbyid(r.id.remark); statuss = (textview) view.findviewbyid(r.id.statuss); btngetdata = (button) view.findviewbyid(r.id.getdata); btngetdata.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { new jsonparse().execute(); } }); activity = this.getactivity(); homecoming view; } private class jsonparse extends asynctask<string, string, jsonobject> { private progressdialog pdialog; @override protected void onpreexecute() { super.onpreexecute(); pdialog = new progressdialog(activity); pdialog.setmessage("getting info ..."); pdialog.setindeterminate(false); pdialog.setcancelable(true); pdialog.show(); } @override protected jsonobject doinbackground(string... args) { jsonparser jparser = new jsonparser(); // getting json url jsonobject json = jparser.getjsonfromurl(url); homecoming json; } @override protected void onpostexecute(jsonobject json) { pdialog.dismiss(); seek { // getting json array url table2 = json.getjsonarray(table2); (int = 0; < table2.length(); i++) { jsonobject c = table2.getjsonobject(i); // storing json item in variable string number = c.getstring(phonenumber); string info = c.getstring(peoplenumber); string remark = c.getstring(remarks); string statuss = c.getstring(status); // adding value hashmap key => value hashmap<string, string> map = new hashmap<string, string>(); map.put(phonenumber, number); map.put(peoplenumber, info); map.put(remarks, remark); map.put(status, statuss); oslist.add(map); list = (listview) findviewbyid(r.id.list); listadapter adapter = new simpleadapter(activity, oslist, r.layout.list_item, new string[] {phonenumber, peoplenumber, remarks, status}, new int[] {r.id.number, r.id.info, r.id.remark, r.id.statuss}); list.setadapter(adapter); list.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { toast.maketext(activity, "you clicked @ " + oslist.get(+position).get("name"), toast.length_short).show(); } }); } } grab (jsonexception e) { e.printstacktrace(); } } } }
android json parsing listview android-fragments
No comments:
Post a Comment