所以我得到了我循环通过这个字符串数组。一个菜鸟问题,但是,我该如何反转和循环回来?基本上我想要的是“前进”和“后退”功能,因此不必循环整个阵列以回到“a”。谢谢!循环回通过字符串数组
public class FirstActivity extends Activity {
private static int counter = 0;
private TextView exampleTextView;
string exampleText;
private static final String[] EXAMPLESTRINGS = {
"a",
"b",
"c"
};
public void generateText(View v) {
String exampleText = EXAMPLESTRINGS[counter++];
if(counter == EXAMPLESTRINGS.length) {
counter = 0;
}
exampleTextView.setText(exampleText);
}
你尝试过'计数器 - '吗?或者只是'EXAMPLESTRINGS [0]'?有点难以确切知道你的问题是什么,或者你期望如何实现这一点。这听起来像你可能认为数组有点像磁带,只能连续访问 - 事实并非如此。你可以从数组中获得任何值,而不仅仅是“下一个”。 – iamnotmaynard 2013-03-21 18:03:15
http://stackoverflow.com/questions/2297110/java-linkedlist-previous-next可能有助于 – 2013-03-21 18:03:42