我有一组单词。当活动启动时,它会显示一个单词,然后当您单击该屏幕时,它会显示数组中的另一个随机单词。我能够得到这个(有一些帮助),但我有点卡住了。当您单击屏幕显示一个新单词时,如何确保该单词尚未从数组中显示出来。这是我到目前为止。如何阻止阵列中的重复输出?
private String[] myString;
public static final Random rgenerator = new Random();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.study);
//Takes a random item from array and creates string
Resources res = getResources();
myString = res.getStringArray(R.array.list);
String q = myString[rgenerator.nextInt(myString.length)];
//Displays random array string in TextView
TextView wordTextView = (TextView) findViewById(R.id.word);
wordTextView.setText(q);
//Set up click listener for new word
View newWord = findViewById(R.id.word);
newWord.setOnClickListener(this);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.word:
//Takes a random item from array and creates string
String q = myString[rgenerator.nextInt(myString.length)];
//Displays random array string in TextView
TextView wordTextView = (TextView) findViewById(R.id.word);
wordTextView.setText(q);
}
}
是的,我猜那些是我的选择。我是新来的android编程,所以我不确定实现任何选项。如果我有一个开始的位置,我可以弄清楚。有任何想法吗? – 2010-11-07 20:12:38
好吧,这只是java,所以你可以使用'ArrayList'来保存你的单词列表和删除项目,或者保存你显示的单词列表。你是新来的android编程,或一般编程? – 2010-11-07 20:49:23
新的android编程和新的编程。我是一个Web开发人员,所以我有一些JavaScript和XML的经验,但即使如此,编程没有HTML或CSS一边对我来说是新的。 – 2010-11-07 21:40:56