【发布时间】:2016-11-26 17:09:54
【问题描述】:
从一个字符串数组(下面的代码)中,当按下按钮时(下面的代码),我想在 TextView(下面的代码)中随机显示一个字符串。我必须使用 onClick“sendMessage”,然后使用随机字符串生成器吗?我将如何在 Java 中做到这一点?非常感谢!
<resources>
<string-array name="colorArray">
<item>Green</item>
<item>Red</item>
<item>Purple</item>
<item>Blue</item>
<item>Orange</item>
<item>Brown</item>
<item>Yellow</item>
<item>White</item>
<item>Pink</item>
</resources>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="NOT SURE WHAT TO PUT HERE"
android:textSize="76sp"
android:gravity="center"
android:textAllCaps="true"/>
<Button
android:id="@+id/green_button"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/green_button"/>
【问题讨论】: