到目前为止,我的应用程序已经开始运行,但我现在面临一个问题。仅供参考,我的应用程序是关于获取用户输入(用户输入一些句子,应用程序将查找模棱两可的单词并显示其含义)。
这是我的代码:
final String[] words = {"cowboy", "animal" , "monster", "duck"};
final String[] meanings = { "meaning1", "meaning2", "meaning3", "meaning4" };
private void initControls() {
// TODO Auto-generated method stub
text = (EditText) findViewById (R.id.editText1);
view = (TextView) findViewById (R.id.textView1);
clear = (Button) findViewById (R.id.button2);
clear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
text.setText("");
view.setText("");
}
});
ok = (Button) findViewById (R.id.button1);
ok.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
findAmbiguousWord();
}
});
}
private void findAmbiguousWord(){
String string = text.getText().toString();
int index = 0;
for (int i = 0; i < words.length; i++) {
if (string.toLowerCase().contains(words[i].toLowerCase())) {
check = true;
index = i;
}
}
view.setText(check ? meanings[index] : "No ambiguous word/s found.");
}
但每当我输入这样的句子时:
My friend is a cowboy. He is also fond of duck.
它只显示第一个单词,即COWBOY。如何显示其他单词?非常需要和感谢帮助。提前致谢!