Pass Text other than Spinner to EditText


I have a Spinner and an EditText with me that what I select in the Spinner is passed to the EditText but I want another text to be passed, I give an example.

I select "Aquarius (Jan. 20 - Feb. 18)" in my Spinner and in my EditText the same is written, but I want to only write first, that is "Aquarius"

How could I do it? I leave here my code so you can see how I pass the text of my Spinner to my EditText:


public class CustomAdapter extends BaseAdapter {
    Context context;
    int flags[];
    String[] titulo_zodiaco;
    LayoutInflater inflter;

    public CustomAdapter(Context applicationContext, int[] flags, String[] titulo_zodiaco) {
        this.context = applicationContext;
        this.flags = flags;
        this.titulo_zodiaco = titulo_zodiaco;
        inflter = (LayoutInflater.from(applicationContext));

    public int getCount() {
        return flags.length;

    public Object getItem(int i) {
        return null;

    public long getItemId(int i) {
        return 0;

    public View getView(int i, View view, ViewGroup viewGroup) {
        view = inflter.inflate(R.layout.custom_spinner_items, null);
        ImageView icon = (ImageView) view.findViewById(;
        TextView names = (TextView) view.findViewById(;
        return view;


    String[] zodiaco = {"Acuario (Ene. 20 - Feb. 18)", "Piscis (Feb. 19 - Marzo 20)", "Aries (Marzo 31 - Abril 19)", "Tauro (Abril 20 - Mayo 20)", "Géminis (Mayo 21 - Junio 20)", "Cáncer (Junio 21 - Julio 22)", "Leo (Julio 23 - Agosto 22)", "Virgo (Agosto 23 - Sep. 22)", "Libra (Sep. 23 - Oct. 22)", "Escorpio (Oct. 23 - Nov. 21)", "Sagitario (Nov. 22 - Dic. 21)", "Capricornio (Dic. 22 - Ene. 19)"};
    int flags[] = {R.drawable.icon_zod_acuario, R.drawable.icon_zod_piscis, R.drawable.icon_zod_aries, R.drawable.icon_zod_tauro, R.drawable.icon_zod_geminis, R.drawable.icon_zod_cancer, R.drawable.icon_zod_leo, R.drawable.icon_zod_virgo, R.drawable.icon_zod_libra, R.drawable.icon_zod_escorpio, R.drawable.icon_zod_sagitario, R.drawable.icon_zod_capricornio};

    Spinner spin = (Spinner) findViewById(;
    CustomAdapter customAdapter = new CustomAdapter(getApplicationContext(), flags, zodiaco);

public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
        String description = zodiaco[position];

public void onNothingSelected(AdapterView<?> parent) {

asked by UserNameYo 22.01.2017 в 15:30

1 answer


Well, thinking about it quickly, you could use SPLIT for the selected string and use the space between "Aquarius" and "(Jan. 20 - Feb. 18)" as a pattern.

In your code:

public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
    String description = zodiaco[position]; // Lo puedes hacer aquí
    editTextZodiaco.setText(description.split(" ")[0]); // o aquí

When you do the SPLIT, it will return an array and from that array you select the initial position, since it will be in all cases of your array, the word you want to display.

I leave you the official documentation of JAVA. link

answered by 22.01.2017 / 19:38