简体   繁体   English

如何在Spinner中获取选定项以显示TextView

[英]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();
    }
}

I have 6 text Views in the layout that matches this class. 我在布局中有6个文本视图与此类匹配。 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. 它们都设置为Visibility“off”,我希望与微调器中的项目对应的那个设置为可见。

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);
   }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM