Android: Storing selected ListView item in global variable -
i have 2 activities.
the first activity contains listview widget populated such:
string products[] = {"pull restaurant names here", "res. 1", "res abc", "res foo", "res hello", "res xyz", "res test", "res test2", "denny's"}; lv = (listview) findviewbyid(r.id.listview); // adding items listview adapter = new arrayadapter<string>(this, android.r.layout.simple_list_item_1, products); lv.setadapter(adapter); once user selects item list, load new activity such:
lv.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { android.content.intent intent = new android.content.intent(guestpage.this, restaurantprofile.class); startactivity(intent); } }); i want able store selected item string listview global variable. have global class extends application, have included necessary name tag in manifest. using similar to:
globals g = (globals)getapplication(); g.setdata(string s); in order set global variable.
my issue storing selected listview item because don't know how call it. not using xml item files populate listview. how know item selected , how store global variable?
for example: user selects "res foo". new activity loaded , have global variable use among activities contains string "res foo". thanks.
what you're doing globals bad practice. instead take solution passing data between activities.
https://stackoverflow.com/a/7325248/3474528
to selected string want like:
public void onitemclick(adapterview<?> parent, view view, int position, long id) { string selected = products[position]; .... }
Comments
Post a Comment