kcirtap1662 kcirtap1662 - 2 months ago 6
Java Question

How would you set the value of a textview based on a value of a spinner?

I am trying to set the value of a textview based on what is selected in the spinner. For example if the cubs were the first element in the list and selected it would set the textview to their hometown. This is what I have so far but it seems to not update the textview.

public void onItemSelected (AdapterView < ? > parent, View view,int position, long id){
TextView mTextView = (TextView) findViewById(R.id.textView);

if(R.id.spinner == 0){
mTextView.setText("Chicago");
}

Answer

This condition doesn't seem to make sense:

if(R.id.spinner == 0){
   mTextView.setText("Chicago");
}

I think what you want to do is check the int position parameter instead:

if(position == 0){
   mTextView.setText("Chicago");
}