Search code examples
javaandroidandroid-studiotextviewspinner

display the word in the selected spinner in the textview


I try to explain by showing as many examples as possible, I chose a word from the spinner, for example it is "cat", after I select it in the spinner i.e. after I click it should also appear in the textview.

Spinner click "cat" TextView change "cat"

I again click Spinner "dog" TextView change "dog"

now my not full code:

```Spinner sababspinner = findViewById(R.id.Sababspinner);
    sababspinner.setOnItemClickListener(this);
}

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
}

@Override
public void onNothingSelected(AdapterView<?> parent) {

}

}```

  • all spinner texts in string.xml

Solution

  • Make an ArrayList with your spinner dataset, then in the onItemSelected method write something like textView.setText(dataset.get(position)).