在研究一些(已知为优秀的)代码时,我可以看到逻辑如下:
if (getContext() instanceof Activity) {
inflater=((Activity)getContext()).getLayoutInflater();
}
else {
inflater=LayoutInflater.from(getContext());
}
我想知道为什么要使用这个if/else
,是否在所有情况下都可以只使用LayoutInflater.from
?