I did not find any boolean method does this task. Can I do this by checking if the id
of the viewStub
changed to the one specified as inflatedid
?
Javacode:
protected void plantViewTree() {
// TODO Auto-generated method stub
ViewStub mViewstub = (ViewStub) findViewById(R.id.viewStub00);
if (mViewStub is inflated) {
//do somthing
}else
mViewstub.inflate();
}
Update Comments on th eOutput
According to this code, the toast
always displays its message, which mean since mViewStub
is assigned to findViewById
it is never null except the viewstub
view in the underlaying alyout is not available. Any suggestions.?
protected void plantViewTree() {
// TODO Auto-generated method stub
ViewStub mViewstub = (ViewStub) findViewById(R.id.viewStub00);
if (mViewstub != null)
Toast.makeText(getApplicationContext(), "view is inflated",
Toast.LENGTH_LONG).show();
else
mViewstub.inflate();
}
We can view the
ViewStub
source code, the most important method isinflate()
,Notice this line
parent.removeViewInLayout(this)
,it had removed in layout after inflate.so we can check if a viewStub is already inflated by this way.