私はプログラミングが初めてです。私はそれに約150の文字列を持つ値という名前の文字列配列を持っています。大量のif文を使用するのではなく、forループを使用してループを繰り返すたびに、配列内の次の要素にループがインクリメントされます。私はそれが超簡単な修正だと確信していますが、私はそれを解決できません。アドバイスありがとう!Java - forループの文字列配列を循環
routeListView.setOnItemClickListener(
new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String route = values[position];
int i;
for (i=0; i < values.length;i++) {
if (route.equals(values[0])) {
Intent intent = new Intent(view.getContext(), RouteDetails.class);
intent.putExtra("route", routeDetail[0]);
startActivity(intent);
}
values++;
}
/*if (route.equals(values[0])) {
Intent intent = new Intent(view.getContext(), RouteDetails.class);
intent.putExtra("route", routeDetail[1]);
startActivity(intent);
}
if (route.equals("Main Wall")) {
Intent intent = new Intent(view.getContext(), RouteDetails.class);
intent.putExtra("route", "Map of Main Wall");
startActivity(intent);
}
if (route.equals("1. Shark Bait - 5.9")) {
Intent intent = new Intent(MainActivity.this, RouteDetails.class);
intent.putExtra("route", "Shark Bait");
startActivity(intent);
}
*/
}
このコードはコンパイルできますか? 'values'は' String [] 'ですが、' values ++ 'を使ってどのようにインクリメントできますか? –