0
我正在使用ViewStub
Android組件進行測試。我可以膨脹一個View
並替換一個新的,但是當我執行一個新的替換現有的View
,我懷疑這個驅逐艦從來沒有在舊的替換Views中被調用過。這裏是我的邏輯示例代碼:Android ViewStub管理替換內部視圖
protected void testInflateReplaceViewStub(){
//case inflating a View...
View viewInflated = View.inflate(getContext(), R.layout.container_view, this); //container View
ViewStub viewStub = (ViewStub) findViewById(R.id.view_stub_impl); //view inside layout
viewStub.setLayoutResource(R.layout.container_view); //fill with some content
View viewStubInflated = viewStub.inflate();
//end inflating the first ViewStub
//case replacing above View by a new one...
viewStubInflated.invalidate(); //this should destroy old inner Views??
viewInflated = View.inflate(getContext(), R.layout.container_view, this);
viewStub.setLayoutResource(R.layout.new_content);//fill new content
viewStubInflated = viewStub.inflate();
//end replacing inflating
}
我想強制銷燬所有舊的換成Views
。