0

As I am new to android development i struck up with a problem where i am unable to set data to spinner adapter..

Here i am getting data from database is like

String times = [09:30,10:30,12:15,04:45,10:50] I am getting array in this pattern. When i am trying to set this array to spinner adapter it's getting error...

 dateadp=new ArrayAdapter<CharSequence>(this, android.R.layout.simple_spinner_dropdown_item,times);
 datespn.setAdapter(dateadp);

so how to convert the following array to string array and how i can append that data to spinner. Can anyone help me with this....

0

2 Answers 2

1

If

["09:30","10:30","12:15","04:45","10:50"] represents String abc.

Then you can take following approach.

String processingString = abc.substring(abc.indexOf("[") + 1,
abc.indexOf("]"));

String[] arr = processingString.split(",");

ArrayAdapter < String > adapter = new ArrayAdapter < String > (this,
android.R.layout.simple_list_item_1, arr);
Sign up to request clarification or add additional context in comments.

Comments

1

I think you struck with converting arraylist to String array. if you are getting data into the arraylist then the code is here.

ArrayAdapter<String> dateadp;
timesArray= times.toArray(new String[times.size()]);
dateadp=new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item,timesarray);
datespn.setAdapter(dateadp);

1 Comment

I tried this. In spinner it is setting values as array only.. ["09:30","10:30","12:15","04:45","10:50"]

Your Answer

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