java - return value without modifiying -


i using setter getter method in app. class contains setter&getter is:

public class product {      private  arraylist<integer> id=new arraylist<integer>();      public arraylist<integer> getid() {         return id;     }      public void setid(arraylist<integer> id) {         this.id = id;     } }  public class check extends activity {      arraylist<integer> passedid=new arraylist<integer>();      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_checkout_page);          intent checkoutintent=getintent();         intent shopcart=getintent();          product prodobj=new product();         passedid=prodobj.getid();             new longrunninggetio().execute();        } } 

when want use getid() method object of product class, returning every time null value. there way return id value stored in setid() method.thanks in advance.

is there way return id value stored in setid() method.

i'm little confused approach. want particular id list returning whole list. return parcitular integer list? need implement method adding values list.

it returning every time null value

your list cannot returned null since in code initilised it.

update:

arraylist<integer> passedid = new arraylist<integer>(); product prodobj = new product(); passedid = prodobj.getid(); 

this absolutely doesn't make sence. look, here created new arraylist passedid empty it's assigned next empty arraylist.

if want pass data via intents need use intent's methods:

putintegerarraylistextra(key, value) // putting data intent getintegerarraylistextra(key) // retrieving data intent 

can suggest me changes in product class posted in question

so want add items list need create method achieve goal:

public void add(int item) {    this.id.add(item); } 

or create arraylist, fill values , use setter well:

arraylist<integer> list = new arraylist<integer>(); list.add(1); list.add(3); product product = new product(); product.setid(list); 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -