gpt4 book ai didi

java - android按钮不断生成字符串

转载 作者:行者123 更新时间:2023-12-01 13:14:29 26 4
gpt4 key购买 nike

当我按下按钮时,它会随机打印其中一个字符串,但我只能执行一次,然后我必须重新启动应用程序并再次按下才能打印新字符串。我必须做什么才能连续按下按钮并连续随机打印字符串?

public String converse = randomStarter();

public String randomStarter() {
Random generator = new Random();
int rand = generator.nextInt(6);
String starter = new String("");

switch (rand) {
case 0: starter = "What was your favorite subject in \n school as a kid? \n Worst?";
break;

case 1: starter = "My favorite room in the house is...";
break;

case 2: starter = "If you had 1 million dollars, what would you do with it?";
break;

case 3: starter = "Did you ever have a nickname? \n If so, what was it?";
break;

case 4: starter = "If I had magical powers I would...";
break;

case 5: starter = "If you were invisible for a day, \nwhat would you do?";
break;

case 6: starter = "5 people I would NOT like to meet...";
break;
}

return starter;
}

文本字段的 xml 代码:

   <TextView android:id="@+id/fullscreen_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true"
android:textColor="#2f4b66"
android:textStyle="bold"
android:textSize="50sp"
android:gravity="center"
android:text="@string/dummy_content" />

最佳答案

您的代码暗示您使用 converse 作为“随机”字符串。如果您想生成新的随机字符串,则必须每次调用 randomStarter()

如果不是这种情况,请显示您使用随机字符串的代码。

关于java - android按钮不断生成字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22583375/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com