0

I have to develop an one android application.

Here i have to get the list of items and set that list of item value in android spinner.

So i have using following code:

if (getIntent().getExtras() !=null) {
    retailerNamesList = (ArrayList<RetailerNames>) getIntent().getExtras().getSerializable("RetailerName");

    for (int i=0;i<retailerNamesList.size();i++) {}

    mRetailerNameAdapter = new RetailerNamesAdapter(WatchList.this,retailerNamesList);
    retailerlist.setAdapter(mRetailerNameAdapter);
}

Here i get the list of arraylist values in that spinner.but i have to split these values and set it in android spinner.please help me.how can i do ???

EDIT:

In the above code am getting the output like:

[com.example.RetailerNames@41216470]

But i need to get the output like:

String[] period_timings={"0-2 days","Within a Week","Within a Month"};

That list have to split and get the values in string[].How can i write the code for these ??? please provide me solution for these ???

3
  • use this retailerNamesList.get(i). Commented Jun 24, 2013 at 12:45
  • Do you want to get a String[] from an ArrayList of RetailerNames ? Commented Jun 24, 2013 at 12:51
  • @blackbelt yes i have to get the String[] from that ArrayList of RetailerName.What's the solution for these ??? Commented Jun 24, 2013 at 12:58

1 Answer 1

2
 for (int i=0;i<retailerNamesList.size();i++){
     retailerNamesList.get(i);
 }

or if you really have to create an array of it then

 final int nameListSize = retailerNamesList.size();
 String []names = new String[nameListSize];
 for (int i=0;i<nameListSize ;i++){
     names[i] = retailerNamesList.get(i);
 }
 // use the string array names to set wherever u need.
Sign up to request clarification or add additional context in comments.

3 Comments

i have using below code means am getting the o/p like:06-25 10:21:55.346: I/System.out(1141): [Ljava.lang.String;@4118f598 ...please provide me solution for my updated question. final int nameListSize = retailerNamesList.size(); String []names = new String[nameListSize];
@user2218667 Implement a toString() method in your RetilerNames class. You can autogenerate that method using eclipse: right click on your class->Source->Generate toString(). The string you return from that method, will be used for printing the object.
I got the output.Thanks for your valuable answer.here i have learned tostring autogenerate method.Thank you so much.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.