I have a switch with many cases and same code and I want to pass it to a for to reduce code but it gives me a programming error. How can I do it?
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
switch(position) {
case 0:
Intent i = new Intent(Inicio.this, OpActivity.class);
i.putExtra("exp", Operaciones[0][1]);
i.putExtra("sab", Operaciones[0][2]);
i.putExtra("dificultad", Operaciones[0][3]);
i.putExtra("op", Operaciones[0][4]);
i.putExtra("stage", 0);
startActivity(i);
break;
case 1:
Intent i2 = new Intent(Inicio.this, OpActivity.class);
i2.putExtra("exp", Operaciones[1][1]);
i2.putExtra("sab", Operaciones[1][2]);
i2.putExtra("dificultad", Operaciones[1][3]);
i2.putExtra("op", Operaciones[1][4]);
i2.putExtra("stage", 0);
startActivity(i2);
break;
.......
}
I want to transform it into a for like this: list.setOnItemClickListener (new AdapterView.OnItemClickListener () {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
for(position=0; position<6; position++){
Intent i[position] = new Intent(Inicio.this, OpActivity.class); //esta linea da error
i[position].putExtra("exp", Operaciones[0][1]);
i[position].putExtra("sab", Operaciones[0][2]);
i[position].putExtra("dificultad", Operaciones[0][3]);
i[position].putExtra("op", Operaciones[0][4]);
i[position].putExtra("stage", 0);
startActivity(i[position]);
}
}