java - Getting text from previous activity and adding it another activities list view -
how add items list dynamically when button clicked? text added listview
. @ moment adds 1 item list view, , when try add changes added item in list.
here code:
this button on click activity gets text:
schedule.setonclicklistener(new onclicklistener() { public void onclick(view view) { addschedule(); intent = new intent(scheduleactivity.this, mainactivity.class); string str = event_name.gettext().tostring(); i.putextra("myextra", str); startactivity(i); } });
then in activity b gets text activity b adds
final listview listview = (listview) findviewbyid(r.id.listview); adapter = new arrayadapter(this, android.r.layout.simple_list_item_1, list); listview.setadapter(adapter);
intent = getintent(); if (i.hasextra("myextra")) { list.add(i.getstringextra("myextra")); adapter.notifydatasetchanged(); }
you see 1 item in new activty's list, since activity created each time via startactivity(intent) (i suppose). each time open activity b, it's new instance. arraylist empty.
you need keep track of items clicked in activity , send whole list activity b, every time. activity b should complete list in intent , create gui-list.
make class implement parcelable or serializable
(slower).
Comments
Post a Comment