android - How to pass a string from a list in one activity to another -
what convert list of user string , on click pass selected string next activity. tried on messaging feature have used on app , has worked fine. attempting work gallery feature. section supposed find users in parse, convert them string , display them on list view. on click supposed collect string on list , use in gallery view activity display images username equal 1 selected list.
listuseractivity
list view of usernames saved in database.
//display clickable list of users private void setconversationslist() { currentuserid = parseuser.getcurrentuser().getobjectid(); names = new arraylist<string>(); parsequery<parseuser> query = parseuser.getquery(); query.wherenotequalto("objectid", currentuserid); query.findinbackground(new findcallback<parseuser>() { public void done(list<parseuser> userlist, com.parse.parseexception e) { if (e == null) { (int i=0; i<userlist.size(); i++) { names.add(userlist.get(i).getusername().tostring()); } userslistview = (listview)findviewbyid(r.id.userslistview); namesarrayadapter = new arrayadapter<string>(getapplicationcontext(), r.layout.user_list_item, names); userslistview.setadapter(namesarrayadapter); userslistview.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> a, view v, int i, long l) { openconversation(names, i); } }); } else { toast.maketext(getapplicationcontext(), "error loading user list", toast.length_long).show(); } } }); }
what happens on clicking name on list view.
public void openconversation(arraylist<string> names, int pos) { parsequery<parseuser> query = parseuser.getquery(); query.whereequalto("username", names.get(pos)); query.findinbackground(new findcallback<parseuser>() { public void done(list<parseuser> user, com.parse.parseexception e) { if (e == null) { // intent intent = new intent(getapplicationcontext(), gridactivity.class); intent intent = new intent(listusersactivity.this, gridactivity.class); intent.putextra("recipient_id", user.get(0).getobjectid()); startactivity(intent); } else { toast.maketext(getapplicationcontext(), "error finding user", toast.length_short).show(); } } }); }
galleryactivity
i've tried convert recipient_id string variable called recipientid , add in line query.whereequalto("username", recipientid);
keeps creating message telling me null.
@override protected void doinbackground(void... params) { // create array intent intent = getintent(); recipientid = intent.getstringextra("recipient_id"); currentuserid = parseuser.getcurrentuser().getobjectid(); phonearraylist = new arraylist<phonelist>(); try { parsequery<parseobject> query = new parsequery<parseobject>("imageupload"); usernametxt = usernameimgshow.gettext().tostring(); //query.whereequalto("username", userstr); query.whereequalto("username", recipientid); query.orderbyascending("createdat"); ob = query.find(); (parseobject country : ob) { parsefile image = (parsefile) country.get("imagefile"); phonelist map = new phonelist(); map.setphone(image.geturl()); phonearraylist.add(map); } } catch (parseexception e) { log.e("error", e.getmessage()); e.printstacktrace(); } return null; }
if second activity's launch mode singleinstance or singletop , it's created when send intent desired intent arrive in onnewintent. if case, current getintent returns intent when activity first created.
Comments
Post a Comment