[英]How do I check the type of a widget programmatically in Android?
I want to check the type of a widget programmatically. 我想以编程方式检查窗口小部件的类型。
View v = tabHost.getTabWidget().getChildAt(i);
How do I check if v
is a RelativeLayout
or LinearLayout
? 如何检查v
是RelativeLayout
还是LinearLayout
?
View v = tabHost.getTabWidget().getChildAt(i);
if(v instanceof RelativeLayout) {
// RelativeLayout
} else if (v instanceof LinearLayout){
// LinearLayout
}
Although you probably should use findViewById()
to find the Widget
you want. 虽然你可能应该使用findViewById()
来找到你想要的Widget
。
View v = tabHost.getTabWidget().findViewById(R.id.myLinearLayoutView);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.