开发者

Android Programmatically created Button Persistence

So in an app I'm messing around with I programmatically create some buttons. Then I setContentView(); to a different page. Then if I come back to the original page (on which I placed the programmatically created buttons), they no longer exist. I guess this makes sense as I am cal开发者_如何学Goling setContentView(R.layout.main); again which is just the original xml file with no data pointing to the buttons. So is there a way to have the buttons persist over such screen transitions? Thanks.


Why not use separate activities for each page? You'll get back stack behavior and preservation of activity state automatically.


Use

.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP)

in your Intent when you are starting the Activity which contains the Buttons.

I think this will solve your problem

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜