我有一个Activity
从中我得到了一些我以后必须使用的输入。我得到一个Integer
编号 NumberPicker
和一个ArrayList<String>
从多项选择中AlertDialog
。在那Activity
我还有一个启动“游戏”的按钮。单击按钮时我想打开一个新的 Activity
所以我可以使用Integer
编号和 ArrayList
但如果我去一个新的 Activity
我会失去它们。所以我的猜测是我应该创建一个新的 Layout
从当前Activity
并在那里处理输入。我需要一些TextViews
以及一个可以在单击按钮时动态更改的计数器。例如第一个TextView
将是 ArrayList
的第一个元素。单击按钮时,计数器必须加 1(计数器 += 1)。当计数器等于Integer
时编号 NumberPicker
(用户输入)TextView
必须从 ArrayList(first element)
更改至ArrayList(second element)
。我不需要逻辑方面的帮助。这只是为了澄清事情。我需要知道如何动态地使用布局来做到这一点。我需要一些指导,我该如何做到这一点,或者这是要走的路(布局不是 Activity
)。教程链接/示例/建议将对我有很大帮助。
最佳答案
When the button is clicked I want to open a new Activity so I can use the Integer number and the ArrayList but I will lose them if I go to a new Activity.
查看putStringArrayListExtra()
Intent
类中的方法。这将允许您将 ArrayList
传递给新的 Activity
:
List<String> stringArrayList = new ArrayList<>();
int intValue = 5;
Intent i = new Intent(ActivityOne.this, ActivityTwo.class);
i.putExtra("int_key", intValue);
i.putStringArrayListExtra("string_key", stringArrayList);
startActivity(i);
关于java - Android关于在Activity中创建新布局并动态更改布局内项目的建议,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33855287/