Thomas
Thomas

Reputation: 293

How to get Selected item in a Spinner to show a TextView

Hey I was wondering if someone could help me edit my code to show a Text View rather than a class. Thanks for any help.

Current Code:

public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
    String classSpot = classes[pos];
    try {
        Class nextClass = Class.forName("com.example.famouspeople." + classSpot);
        final Context context = this;
        Intent intent = new Intent(context,nextClass);
        startActivity(intent);

    }
    catch(ClassNotFoundException e){
        e.printStackTrace();
    }
}

Upvotes: 0

Views: 726

Answers (1)

Simon Dorociak
Simon Dorociak

Reputation: 33505

I have 6 text Views in the layout that matches this class. They are all set to Visibility "gone" and I would like the one that corresponds to the item in the spinner to be set to visible.

So this shouldn't be tricky. So you have implemented listener and make desired action.

public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
   String val = someFunction();
   if (val.equals("somevalue")) {
      textView.setVisibility(TextView.VISIBLE);
   }
}

Upvotes: 2

Related Questions