我给你看两个例子:
示例 A:
protected void mostrarCms(int idCms) {
LinearLayout variableContent = (LinearLayout) this.findViewById(R.id.variableContent);
loopDeCms:
for (int i=0; i<variableContent.getChildCount();i++){
View fillActual = variableContent.getChildAt(i);
if (fillActual instanceof WebView){
WebView wbActual = (WebView) fillActual;
if (wbActual.getContentDescription().toString().equals("cms_id_"+idCms)){
wbActual.setVisibility(View.VISIBLE);
break loopDeCms;
}
}
}
}
示例 B:
protected void mostrarCms(int idCms) {
LinearLayout variableContent = (LinearLayout) productView.this.findViewById(R.id.variableContent);
for (int i=0; i<variableContent.getChildCount();i++){
View fillActual = variableContent.getChildAt(i);
if (fillActual instanceof WebView){
WebView wbActual = (WebView) fillActual;
if (wbActual.getContentDescription().toString().equals("cms_id_"+idCms)){
wbActual.setVisibility(View.VISIBLE);
return;
}
}
}
}
这两个推荐哪一个?请注意,此代码来自 Android,因此是否使用/释放资源实际上很重要。