java - Arraylist<Class> passing to another activity for adding objects in that activity returning 1st activity displaying them -
my first activity in have arraylist initialized , must passed custom array-adapter adding objects array list. here first activity.
public class ordersummary extends appcompatactivity { arraylist<order> orderitems= new arraylist<>(); @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.lview); orderadapter orderarrayadapter = new orderadapter(this,orderitems); listview listview = (listview) findviewbyid(r.id.satya); listview.setadapter(orderarrayadapter); } public arraylist<order> getorderitem() { return this.orderitems; } }
second activity custom adapter adding objects arraylist<custom class>
. elements added on button
click.
final button buttonname = (button) listitemview.findviewbyid(r.id.listitems_addcart); if ( currentposition != null ) { buttonname.settext(currentposition.getbuttonnname()); buttonname.setonclicklistener(new view.onclicklistener() { private int index; context context = getcontext(); @override public void onclick(view v) { if ( currentposition.getcount() == 0 ) { order o = new order(currentposition.getmprice(), currentposition.getmitemname(), currentposition.updatecount()); obj.getorderitem().add(o); index = obj.getorderitem().indexof(o); toast.maketext(context, "the" + currentposition.getmitemname() + currentposition.getcount() + " no has been added", toast.length_short).show(); } else { toast.maketext(context, " " + currentposition.getmitemname() + obj.getorderitem().get(index).updatequantity() + " no has been added", toast.length_short).show(); } } } ); ... }
i used getter method passing arraylist
custom adapter. output must when open first activity must show data added using button click initialized intents. full custom adapter code used display content in listview.
import java.util.arraylist; import static satya_mydream.srkrcanteen.r.layout.word_items; //custom word adapter used display , hanndle row_iem class wordadapter extends arrayadapter<word> { private ordersummary obj = new ordersummary(); wordadapter(activity context, arraylist<word> items) { super(context, 0, items); } @nonnull @override public view getview(int position, view convertview, @nonnull viewgroup parent) { // check if existing view being reused, otherwise inflate view view listitemview = convertview; if ( listitemview == null ) { listitemview = layoutinflater.from(getcontext()).inflate( word_items, parent, false); } // {@link androidflavor} object located @ position in list final word currentposition = getitem(position); // find textview in list_item.xml layout id version_name // find textview in list_item.xml layout id version_number final textview itemtextview = (textview) listitemview.findviewbyid(r.id.listitems_item); // version number current androidflavor object , // set text on number textview if ( currentposition != null ) { itemtextview.settext(currentposition.getmitemname()); } textview dollartextview = (textview) listitemview.findviewbyid(r.id.listitems_dollor); // version number current androidflavor object , // set text on number textview if ( currentposition != null ) { dollartextview.settext(currentposition.getdollar()); } final button buttonname = (button) listitemview.findviewbyid(r.id.listitems_addcart); if ( currentposition != null ) { buttonname.settext(currentposition.getbuttonnname()); buttonname.setonclicklistener(new view.onclicklistener() { private int index; `enter code here` context context = getcontext(); @override public void onclick(view v) { if ( currentposition.getcount() == 0 ) { order o = new order(currentposition.getmprice(), currentposition.getmitemname(), currentposition.updatecount()); obj.getorderitem().add(o); index = obj.getorderitem().indexof(o); toast.maketext(context, "the" + currentposition.getmitemname() + currentposition.getcount() + " no has been added", toast.length_short).show(); } else { toast.maketext(context, " " + currentposition.getmitemname() + obj.getorderitem().get(index).updatequantity() + " no has been added", toast.length_short).show(); } } } ); } textview pricetextview = (textview) listitemview.findviewbyid(r.id.list_items_price); if ( currentposition != null ) pricetextview.settext(currentposition.getmprice()+""); /*find imageview in list_item.xml layout id list_item_icon imageview iconview = (imageview) listitemview.findviewbyid(r.id.list_item_icon); image resource id current androidflavor object , set image iconview iconview.setimageresource(currentandroidflavor.getimageresourceid()); return whole list item layout (containing 2 textviews , imageview) can shown in listview */ return listitemview; } }
Comments
Post a Comment