1

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 the other two ?


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

Thanks

xain
  • 12,180
  • 17
  • 72
  • 118

3 Answers3

2

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

xain
  • 12,180
  • 17
  • 72
  • 118
1
 if(child.getClass() instanceof Spinner.class){
 ...

edit:

I found Stackoverflow question that explain it:

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

Community
  • 1
  • 1
pawelzieba
  • 16,024
  • 3
  • 43
  • 72
1

Have you considered using

if(child instanceof EditText){}
else if(child instanceof TextView){}
else if(child instanceof Spinner){}
runor49
  • 3,770
  • 1
  • 20
  • 18