android - Retrieving Parse ObjectID in OnTimeClickListener method -
i want retrieve objectid of item (to specific, it's class called "room" in our parse model) clicked within listview
. , after that, want pass retrieved objectid class using intent
.
i tried parse docs' getobjectid(); method seems won't work. how should retrieve it?
here's code.
button createbtn; button searchbtn; button mygroupbtn; button settingbtn; string[] courses; list<string> listitems; arrayadapter<string> adapter; listview listview; textview textview; // when creat button tapped public void createbtn(view view){ intent = new intent(getapplicationcontext(), create.class); // removes animation i.addflags(intent.flag_activity_no_animation); startactivity(i); } // when setting button tapped public void settingbtn(view view) { intent = new intent(getapplicationcontext(), setting.class); // removes animation i.addflags(intent.flag_activity_no_animation); startactivity(i); } @override protected void oncreate(bundle savedinstancestate) { intent intent = getintent(); string coursename = intent.getstringextra("coursename"); string coursenumber = intent.getstringextra("coursenumber"); super.oncreate(savedinstancestate); setcontentview(r.layout.activity_search_result); // making links buttons on create createbtn = (button) findviewbyid(r.id.createbtn); searchbtn = (button) findviewbyid(r.id.searchbtn); mygroupbtn = (button) findviewbyid(r.id.mygroupbtn); settingbtn = (button) findviewbyid(r.id.settingbtn); //chaning button colors searchbtn.settextcolor(0xffffffff); createbtn.settextcolor(0xffbfbfbf); mygroupbtn.settextcolor(0xffbfbfbf); settingbtn.settextcolor(0xffbfbfbf); listview= (listview)findviewbyid(r.id.listview); textview= (textview)findviewbyid(r.id.textview2); textview.settext(coursename + " " + coursenumber); listitems = new arraylist<>(); parsequery<parseobject> roomquery = parsequery.getquery("room"); roomquery.whereequalto("course" , coursename); roomquery.whereequalto("number" , coursenumber); roomquery.findinbackground(new findcallback<parseobject>() { @override public void done(list<parseobject> objects, parseexception e) { if (e == null) { (parseobject room : objects) { log.i("appinfo", string.valueof(room.get("title"))); string stringtoadd = ""; string opened = string.valueof(room.get("opened")); string x; if(opened.equals(true)){ x = "open"; }else{ x = "closed"; } stringtoadd = stringtoadd + string.valueof(room.get("studydate")) + " " + string.valueof(room.get("category")) + " " + x + "\n" + string.valueof(room.get("title")) + " " ; listitems.add(stringtoadd); log.i("appinfo", "a"); } } else { log.i("appinfo", "b"); e.printstacktrace(); } } }); initlist(); } public void initlist() { log.i("appinfo", "c"); adapter = new arrayadapter<string>(this, r.layout.list_two, r.id.txtvw, listitems); listview.setadapter(adapter); listview.setonitemclicklistener(this); } @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { intent intent = new intent(getapplicationcontext(), room.class); string category = listitems.get(position); }
}
your problem loose objectid
of parse in "adapter
": use strings
, basic android adapter
(there: new arrayadapter<string>(this, r.layout.list_two, r.id.txtvw, listitems);
) display elements; problem converting complicated room object string
not contain lot of informations makes loose objectid
want keep.
the solution problem android-ish pattern called adapter
or more case custom adapter
explain device how render room
elements every cell of app's listview
.
it extremely documented (much better possibility write in post) here generic official doc , here is, me, the best tutorial concept.
ps: beginner, recommend base adapter, is, me, simplest :)
Comments
Post a Comment