2011-03-23 67 views
1

通過查看的組件迭代下面的代碼工作:問題檢測Spinner組件

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

但這並不:

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

什麼是微調類的其他兩個之間的區別?


是我的錯......我previousy檢查,如果它是一個ViewGroup對象,因此它從來沒有達到條件

感謝

+0

考慮使用的instanceof。它將支持子類。 – pawelzieba 2011-03-23 18:05:49

回答

2

我錯認爲...我previousy檢查,如果它是一個ViewGroup對象,因此它從來沒有達到條件

1

你有沒有使用

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