Jo Jo Roid Jo Jo Roid - 2 months ago 9
Java Question

How can I get previous value java?

I have tow

Spinner dropDown
on my
layout
when user select each of spinner I'll take an id from
spinner
,and I have a class that I send these Ids to it class .

the
getID.class
:

public class getID {
private String tagID = "105358";

public getID tagID(String tagID) {

this.tagID += "," + tagID;

return this;
}
public URL build() throws MalformedURLException {
return new URL(
String.format("%s",
tagID));
}
}


Problem :

But when I select an item on second spinner I lost the first Value of the first spinner .

I send my value to class with this code:

URL url = new getID(Const.URLMedia)
.tagID("10")
.build();


For example when I select an item on first spinner(for exam I send 10 value) in other class I see :

105358,10


when I select an Item on second spinner(for exam I send 85 value) in other class I see :

105358,85


But I need to :

105358,10,85

Answer

Seems like you are creating a new instance of getID

URL url = new getID(Const.URLMedia)
                                .tagID("10")
                                .build(); 

so when you select the first spinner you get 105358,10 and when you select second, your code will again create new instance of getID and you get 105358,5 so simply create a singe getID instance instead of creating new every time.

class Activity ..{
getID  url;

         @Override
          oncreate (Bundle saveinstance){
          url=new getID();
        }
  }

Now simple appends the value

URL url = obj.tagID(StringValue).build(); 

plus i can't see any constructor for this getID(Const.URLMedia),seems like missing.