简体   繁体   English

我如何更新 android 工作室中的活动

[英]How can i update an activity in android studio

I've created an app with two activities.我创建了一个包含两个活动的应用程序。 On the second activity i can create new buttons by pressing a floating action bar button inside the activity;在第二个活动中,我可以通过按下活动内的浮动操作栏按钮来创建新按钮; but the problems is when i return to the main activity and come back all the added buttons are gone.但问题是当我返回主要活动并回来时,所有添加的按钮都消失了。

I was wondering how can i save these added views so whenever i exit that particular activity or the app entirely, views won't perish.我想知道如何保存这些添加的视图,以便当我完全退出该特定活动或应用程序时,视图不会消失。

I know i can save the views' values by "Preferences" commands but that only can save the views' parameters not themselves and if i go that way i have to recreate each view again each time i enter the activity.我知道我可以通过“首选项”命令保存视图的值,但这只能保存视图的参数而不是它们本身,如果我 go 那样我每次进入活动时都必须重新创建每个视图。

if i could update the activity whenever views are added to it that would be excellent.如果我可以在添加视图时更新活动,那就太好了。

I would appreciate any help.我将不胜感激任何帮助。

You can save information about views in preference like number of buttons created.您可以优先保存有关视图的信息,例如创建的按钮数量。 for example you clicked button 4 times then save numOfButtons value as 4. In onCreate method you can check values of numOfButtons and execute that block of code 4 times to generate buttons.例如,您单击按钮 4 次,然后将 numOfButtons 值保存为 4。在 onCreate 方法中,您可以检查 numOfButtons 的值并执行该代码块 4 次以生成按钮。

The activity view itself cannot be preserved as it gets destroyed after it is removed from the stack.活动视图本身无法保留,因为它在从堆栈中移除后被销毁。 However, you can use custom XML layouts and then use them wherever you want.但是,您可以使用自定义 XML 布局,然后在任何您想要的地方使用它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何更新活动(ListView)-Android - How Can I Update the activity(ListView) - android Android Studio Java:如果产品已经存在于我的购物车活动中,我该如何更新我的数量? - Android Studio Java: How can I update my quantity if the product already exist's in my Cart Activity? 如何从 appcompat 活动更改为 Android 工作室中的活动? - How can I change from appcompat activity to Activity in Android studio? 随着Android Studio更新无法启动活动 - With the update to Android Studio can't start activity Android Studio 如何将此活动放入扩展片段中? - Android Studio How can I put this activity in extends Fragment? 如何将数据从服务发送到 Android Studio 中的活动? - How can I send data from a Service to an Activity in Android Studio? 如何将清单发送到Android Studio中的另一个活动 - how can I send a List into another activity in Android Studio 如何在Android Studio中将图像添加到空白活动? - How can i add an image to a blank activity in android studio? 如何在按钮上显示随机活动单击在Android Studio中 - How Can I Display Random Activity On Button Click In Android Studio 如何在Android Studio中的活动中创建移动的背景图像 - How can I create a moving background image in an activity in android studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM