[英]How to get Selected item in a Spinner to show a TextView
嘿,我想知道是否有人可以帮助我编辑我的代码以显示文本视图而不是类。 谢谢你的帮助。
现行代码:
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();
}
}
我在布局中有6个文本视图与此类匹配。 它们都设置为Visibility“off”,我希望与微调器中的项目对应的那个设置为可见。
所以这不应该是棘手的。 所以你已经实现了监听器并做出了所需的动作。
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.