janki janki - 4 months ago 28
Android Question

split value and add in to spinner

want to add pipeline seprated value in to spinner.
I have String defined below.


String value =
12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35;


how to split this value and add it in to spinner.

Answer

You can use the split method to do that:

String values = "12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35";
//to seperate by pipeline
String[] separatedValues = values.split("|");
OR
//to seperate each character individually
String[] separatedValues = values.split("(?!^)")

ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(YourActivity.this, android.R.layout.simple_spinner_item, separatedValues);
spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
yourSpinner.setAdapter(spinnerAdapter);