Could anyone help me to work with spinner and textview in Android studio | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Could anyone help me to work with spinner and textview in Android studio

I had one spinner and i have some dropdown elements in that. and i need to fetch some data from resources file then i have to display it in textview accounting to the Id of the spinner

5th Feb 2017, 11:02 AM
Priyanka sundar
Priyanka sundar - avatar
3 Answers
+ 4
The below code helps in filling the selected spinner item in the textview. TextView textView = (TextView) findViewById(R.id.textView); Spinner spinner = (Spinner) findViewById(R.id.spinner); // Add items to your spinner here (From what I understand, you already did this). // Add OnItemSelectedListener to listen spinner item selections. spinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView adapter, View v, int i, long lng) { String selecteditem = adapter.getItemAtPosition(i).toString(); textView.setText(selecteditem); } @Override public void onNothingSelected(AdapterView<?> parentView) { } });
5th Feb 2017, 11:14 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 3
getApplicationContext().getString(R.string.text1); can be used to access a string named 'text1' in strings.xml
5th Feb 2017, 4:09 PM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 2
it shows only the content which were stored in spinner .. but i have to fetch the resource from the XML file which is stored in the src/main/red/value/string.xml
5th Feb 2017, 12:09 PM
Priyanka sundar
Priyanka sundar - avatar