0
我使用ViewStubs
以編程方式創建一些視圖,如下所示。Android在充氣後查找視圖
RelativeLayout allCommissionsContainer = (RelativeLayout) mBaseLayout.findViewById(R.id.allCommissionsContainer);
ViewStub viewStubCommission = new ViewStub(mActivity);
viewStubCommission.setLayoutResource(R.layout.viewstub_commission_container);
allCommissionsContainer.addView(viewStubCommission);
viewStubCommission.inflate();
但是,如何在代碼後面找到膨脹視圖(RelativeLayout
)?如果我使用viewStubCommission.setTag("MyTag");
是否不適用於實際的ViewStub
而不是膨脹的視圖?我試過,但它給了我一個null pointer exception
。我需要或allCommissionsContainer.findViewWithTag("MyTag")
。