我正在使用以下代码删除每个视图组上的子项:
protected void onDestroy() {
super.onDestroy();
this.liberarMemoria();
}
public void liberarMemoria(){
imagenes.recycleBitmaps();
this.unbindDrawables(findViewById(R.id.RelativeLayout1));
System.gc();
}
private void unbindDrawables(View view) {
if (view.getBackground() != null) {
view.getBackground().setCallback(null);
}
if (view instanceof ViewGroup) {
for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
unbindDrawables(((ViewGroup) view).getChildAt(i));
}
((ViewGroup) view).removeAllViews();
}
}
其中视图:R.id.RelativeLayout1 是一个 ListView。
但是这样做我有一个例外:
E/AndroidRuntime(582): java.lang.RuntimeException: Unable to destroy activity {...}: java.lang.UnsupportedOperationException: removeAllViews() is not supported in AdapterView
我该如何解决这个问题?