开发者

Getting error for while reinflating

I am trying to inflate view stub on Button click. It works fine when the button is pressed for the first time, but when I press the button a second time th开发者_如何学Ce application crashes.

I am Using the following code

 public void display(View V)  //Button Click
    {
         stub=(ViewStub) findViewById(R.id.stub);
         inflated=stub.inflate();

    }

Can anyone give me some help on this?


You can add the following check to avoid trying to inflate the ViewStub several times:

if(stub.getParent() != null) {
    inflated = stub.inflate();
}

Late answer, but maybe it will help someone :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜