android - getStringArrayListExtra output with Square Brackets -
i'm learning android intent. need show list of items when showlist button clicked, without using listview or spinner.here parts of code:
firstactivity class (main)
// add item function public void additem (view v){ if((textutils.isempty(item_in.gettext().tostring()))||(item_in.gettext().tostring().contains(" "))){ input_error_alert.setmessage("data not correct").setpositivebutton("edit data",null).show(); } else{ confirm_alert.setmessage("data correct").setpositivebutton("ok",null).show(); itemlist.add(item_in.gettext().tostring()); item_in.settext(""); } } public void showlist (view v){ //create intent secondactivity intent show = new intent(this,secondactivity.class); bundle b = new bundle(); b.putstringarraylist("itemlist",itemlist); show.putextras(b); startactivity(show); }
secondactivity class
protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_second); list = (edittext)findviewbyid(r.id.shopping_list); intent show = getintent(); arraylist<string> item_list = show.getstringarraylistextra("itemlist"); list.settext("your shopping list includes: "+item_list); }
the output is: "your shoppping list includes: [item1, item2,...]. explain how brackets [] appear in output? how remove it?
thanks lot!
intent show = getintent(); arraylist<string> item_list = show.getstringarraylistextra("itemlist"); stringbuilder s = new stringbuilder(100); for(int i=0; i<= item_list.size(); i++){ s.append(list.get(i) + ","); } list.settext("your shopping list includes: "+s.tostring());
Comments
Post a Comment