开发者

Problem detecting Spinner component

iterating through a View's components the following code works:

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 th开发者_开发技巧e other two ?


My mistake ... I was previousy checking if it was a ViewGroup object so It never reached the condition

Thanks


My mistake ... I was previousy checking if it was a ViewGroup object so It never reached the condition


Have you considered using

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


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

edit:

I found Stackoverflow question that explain it:

Any reason to prefer getClass() over instanceof when generating .equals()?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜