parse.com - How to add data from parse to an Android ListView -
i have parse account. got data parse cannot add arraylist nor listview.
i managed data string not able add list view.
here code:
public class student_login extends activity implements view.onclicklistener { private textview mtextview; arraylist arraylist;; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_student_login); arraylist = new arraylist(); setlisdata(); arrayadapter adapter = new arrayadapter<string>(this, r.layout.activity_list_view, arraylist); listview listview = (listview) findviewbyid(r.id.listview); listview.setadapter(adapter); button sub=(button)findviewbyid(r.id.button2); sub.setonclicklistener(this); } private void setlisdata() { parseuser currentuser = parseuser.getcurrentuser(); string curser = currentuser.getusername().tostring(); final string sc = currentuser.getstring("school"); toast.maketext(getapplicationcontext(), "your id " + sc, toast.length_short).show(); parsequery<parseobject> query = parsequery.getquery("staff"); query.whereequalto("school", sc); query.findinbackground(new findcallback<parseobject>() { @override public void done(list<parseobject> objects, parseexception e) { (parseobject parseobject : objects) { string name = parseobject.getstring("name"); arraylist.add(name); toast.maketext(getapplicationcontext(), name, toast.length_long).show(); } } }); } public void onclick(view v) { switch (v.getid()){ case r.id.button2: // r =movie.getratingstar(); parseuser.logout(); parseuser currentuser = parseuser.getcurrentuser(); // should null isn't... invalidateoptionsmenu(); toast.maketext(getapplicationcontext(), "disconnected...", toast.length_long).show(); intent intent = new intent(this,login.class); startactivityforresult(intent,0); finish(); break; } } }
at runtime output names displayed in toast not adding list view.thank you.
do below changes in code works fine
arrayadapter adapter @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_student_login); arraylist = new arraylist(); adapter = new arrayadapter<string>(this, r.layout.activity_list_view, arraylist); listview listview = (listview) findviewbyid(r.id.listview); listview.setadapter(adapter); button sub=(button)findviewbyid(r.id.button2); sub.setonclicklistener(this); setlisdata(); } private void setlisdata() { parseuser currentuser = parseuser.getcurrentuser(); string curser = currentuser.getusername().tostring(); final string sc = currentuser.getstring("school"); toast.maketext(getapplicationcontext(), "your id " + sc, toast.length_short).show(); if(arraylist.size()>0){ arraylist.clear(); } parsequery<parseobject> query = parsequery.getquery("staff"); query.whereequalto("school", sc); query.findinbackground(new findcallback<parseobject>() { @override public void done(list<parseobject> objects, parseexception e) { (parseobject parseobject : objects) { string name = parseobject.getstring("name"); arraylist.add(name); toast.maketext(getapplicationcontext(), name, toast.length_long).show(); } if(arraylist.size()>0 && adapter != null){ adapter.notifydatasetchanged(); } } }); }
Comments
Post a Comment