我想将按钮的文本设置为随机字母我使用了按钮的设置文本属性并传递了包含随机字母的变量
import java.util.Random;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class OnePlayerEasy extends Activity {
char z;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.oneplayereasy);
}
public void gen(View v) {
Random r = new Random();
String alphabet = "abcdefghijklmnopqrstuvwxyz";
for (int i = 0; i < 1; i++) {
z = alphabet.charAt(r.nextInt(alphabet.length()));
Button button = (Button)findViewById(R.id.button1);//button i want to genrate random no on
button.setText(z);
} // prints random characters
}
}