我正在尝试为 andriod 编写一个应用程序(使用 eclipse),其中当按下图像按钮时,alertdialouge 会从数组中产生一个随机字符串,每次按下按钮时我都希望它更改数组中的字符串. 我编写了一个 alertdialouge 和一些获取随机字符串的代码,但它是针对文本视图而不是 alert dialouge 进行的。你能看看我的代码并告诉我我需要改变什么吗?
package kevin.erica.box;
import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import java.util.Random;
public class TheKevinAndEricaBoxActivity extends Activity {
/** Called when the activity is first created. */
private String[] myString;
private String list;
private static final Random rgenerator = new Random();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources();
myString = res.getStringArray(R.array.myArray);
list = myString[rgenerator.nextInt(myString.length)];
TextView tv = (TextView) findViewById(R.id.textView1);
tv.setText(list);
}
public void kevin(View view)
{
new AlertDialog.Builder(this).setTitle("The Box").setMessage(getResources().getText(R.string.list)).setNeutralButton("Close", null).show(); }
}