我正在尝试创建一个按钮来启动 randomGenerator。
Random randomGenerator = new Random();
int randomInt = randomGenerator.nextInt(9);
String wordList[] = new String[9];
{
wordList[0] = "Mexican";
wordList[1] = "American";
wordList[2] = "Barbeque";
wordList[3] = "Chinese";
wordList[4] = "Indian";
wordList[5] = "Italian";
wordList[6] = "Thai";
wordList[7] = "Viatnamese";
wordList[8] = "Middle Eastern";
}
String wordToDisplay = wordList[randomInt];
这是我的布局,我已经创建了我的按钮并标记了它。只是不知道如何从这里开始。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:padding="@dimen/padding_medium"
android:text="@string/hello_world"
tools:context=".ImHungry" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="@string/button1" />
</RelativeLayout>
谢谢你!