I am trying to use a viewstub to set my view and it works fine the first time however if I call the method again I get a null pointer exception, Any Ideas why this is happening?
here is my code, on the first time around I call this and it works fine.
ViewStub stub = FindViewById<ViewStub>(Resource.Id.stub);
stub.LayoutResource = Resource.Layout.overview;
stub.Inflate();
then when I try to do the same one again with a different layout I get a null pointer exception
ViewStub stub = FindViewById<ViewStub>(Resource.Id.stub);
stub.LayoutResource = Resource.Layout.product_view;
stub.Inflate();
According to the official documentation:
Your
ViewStub
is replaced by theResource.Layout.overview
after you callstub.Inflate()
. You could useFindViewById()
to get view in youroverview
, but can't get theViewStub
any more.