简体   繁体   English

检测Spinner组件的问题

[英]Problem detecting Spinner component

iterating through a View's components the following code works: 迭代View的组件,以下代码有效:

if (child.getClass() == EditText.class) {
  ...
} else if (child.getClass() == TextView.class) {
  ...

but this doesn't: 但这不是:

} else if (child.getClass() == Spinner.class) {
  ...

What's the difference between the Spinner class an the other two ? Spinner类与另外两个类有什么区别?


My mistake ... I was previousy checking if it was a ViewGroup object so It never reached the condition 我的错误......我之前检查过它是否是一个ViewGroup对象所以它从未达到过这个条件

Thanks 谢谢

我的错误......我之前检查过它是否是一个ViewGroup对象所以它从未达到过这个条件

 if(child.getClass() instanceof Spinner.class){
 ...

edit: 编辑:

I found Stackoverflow question that explain it: 我找到了解释它的Stackoverflow问题:

Any reason to prefer getClass() over instanceof when generating .equals()? 有没有理由在生成.equals()时更喜欢getClass()而不是instanceof?

Have you considered using 你考虑过使用吗?

if(child instanceof EditText){}
else if(child instanceof TextView){}
else if(child instanceof Spinner){}

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

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