【发布时间】:2023-03-17 20:37:01
【问题描述】:
我想一个接一个地从String 数组中返回单词。
public String CurrentString(int move) {
int currentString = 0;
EditText ed = (EditText) findViewById(R.id.ed);
String[] strings = ed.getText().toString().split(" ");
int newString = currentString move;
if (newString >= strings.length) {
// if the new position is past the end of the array, go back to the beginning
newString = 0;
}
if (newString < 0) {
// if the new position is before the beginning, loop to the end
newString = strings.length - 1;
}
currentString = newString;
Toast.makeText(getApplicationContext(), strings[currentString],Toast.LENGTH_LONG).show();
return strings[currentString];
}
问题是我上面的代码没有返回所有文本。请帮忙。
【问题讨论】:
-
真的很难理解你的问题,因为代码是别的东西。请修复它!您的代码中也有一些错误! currentString ;??
-
考虑查看 StringTokenizer。
-
“不返回所有文本”...嗯,是的,你从数组中返回一个元素