android - How to add an item multiple times in a ListViewActivity from another ListViewActivity -
this original listview class select item list want select same item 4 times, in activity should add item 4 times. can add 1 time in activity. have used sharedpreferences adding. can me how can store value 4 times?any tips appreciated :((( thanks
//this class select item
public class alcohol extends activity { private list<alcohols> alcohol = new arraylist<alcohols>(); string wine; string beer; sharedpreferences somedata; public static string filename = "mysharedstring"; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_alcohol); somedata = getsharedpreferences(filename, 0); alcohollist(); alcohollistview(); registerclickcallback(); } private void registerclickcallback() { // todo auto-generated method stub listview list = (listview) findviewbyid(r.id.alcohollistview); list.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view viewclicked, int position, long id) { switch (position) { case 0: wine = "wine"; sharedpreferences.editor editor0 = somedata.edit(); editor0.putstring("sharedstring4", wine); editor0.commit(); otheractivity("list"); break; case 1: beer = "beer"; sharedpreferences.editor editor1 = somedata.edit(); editor1.putstring("sharedstring5", beer); editor1.commit(); otheractivity("list"); break; } }); } private void alcohollistview() { // todo auto-generated method stub arrayadapter<alcohol> adapter = new mylistadapter(); listview list = (listview) findviewbyid(r.id.alcohollistview); list.setadapter(adapter); } private class mylistadapter extends arrayadapter<pilstyper> { public mylistadapter() { super(alcohol.this, r.layout.list_item_view, alcohol); } public view getview(int position, view convertview, viewgroup parent) { view itemview = convertview; if (itemview == null) { itemview = getlayoutinflater().inflate( r.layout.activity_item_view, parent, false); } alcohol alcohol = alcohol.get(position); imageview imageview = (imageview) itemview .findviewbyid(r.id.wine); imageview.setimageresource(alcohol.getikonid()); // text textview text = (textview) itemview.findviewbyid(r.id.text_wine); text.settext(alcohol.gettext()); return itemview; } } private void alcohollist() { // todo auto-generated method stub alcohol.add(new alcohol("wine", r.drawable.wine)); alcohol.add(new alcohol("beer", r.drawable.beer)); } public void otheractivity(string a) { intent = new intent(); if (a.equals("list")) { i.setclass(getapplicationcontext(), list.class); } startactivity(i); finish(); } }
here listview class want add item 4 times if have selected 4 times in previous class. can add 1 time ://
public class list extends activity { private list<alcohol> alcohol = new arraylist<alcohol>(); arrayadapter<alcohol> adapter; sharedpreferences somedata; public static string filename = "mysharedstring"; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_item); somedata = getsharedpreferences(filename, 0); string wine = somedata.getstring("sharedstring4", "ooo"); string beer = somedata.getstring("sharedstring5", "ooo"); if(wine.equals("wine")){ alcohol.add(new alcohol("wine", r.drawable.wine)); }else if(wine.equals("wine")){ alcohol.add(new alcohol("beer", r.drawable.beer)); } }
in side onitemclick() store value want pass other activity in array list. list.add() , move other activity 1 submit kind of common button. may can put after list view. , pass list intent.
Comments
Post a Comment