In my android application I am using spinner for selecting data.. and I created string array for strings that to be displayed in spinner. I put all the details in strings folder. I wanted the selected text t be displayed in edit text once the user selected item..
For example : spinner is used to select country codes suppose user selected USA
then the selected text will be like this
United States of America,+001
I don't need t take all the text and display it in edit text. I need only the text after comma, that is +001. So is there any way to get the text after the comma only
Spinner spinner = (Spinner)findViewById(R.id.spinner);
String text = spinner.getSelectedItem().toString();
I know this will display all text I want only text that dislpaying after comma
You can split your text on the comma:
String text = spinner.getSelectedItem().toString(); String splited_text = text.split(","); text = splited_text;
String seperated = spinner.getSelectedItem().toString().split(","); text = seperated;
This will return only "+001".
Suppose the text is in a string name
text. use this:
String temp = text.split(",") String code = temp; //+001 the code after , temp contains the rest
String code = text.substring(text.indexOf(','));