|
Event Handling
Hi to every one!
I have problems with my program, because I have 4 different list:The first list show the possibilities to choose among "photos Russia", "photos Finland" and "Photos Spain". The second list is the Photos Russia list, and the user can choose between 2 pictures to watch. The third list is Photos Finland, and the last one is Phostos Spain.
So, when the user choose, from the first list, "photos Russia",The user must see on the mobile screen the name of the pictures. Then, he can choose one of them, and the picture will be showed on the screen.
My problem is with the method Command Action, because it doesnt work properly. The function is as follows:
public void commandAction(Command c, Displayable d){
if (c == back){ //Selecciono comando “Atrás”
pantalla.setCurrent(listas[0]);
}if (c == back){ //Selecciono comando “Atrás”
pantalla.setCurrent(listas[0]);
}
else if (d==listas[0]){
System.err.println("Entro en la lista 0: \n");
if(c==listas[0].SELECT_COMMAND){// Si selecciono
switch(listas[0].getSelectedIndex()){ //opcion del menu
case 2:{ pantalla.setCurrent(listas[1]);break;}
case 1:{ pantalla.setCurrent(listas[2]);break;}
case 0:{pantalla.setCurrent(listas[3]);break;} // pantalla.setCurrent(listas[3]);break;
}
}
}else if(d==listas[1]){
System.err.println("Entro en la lista 1: \n");
if(c==List.SELECT_COMMAND){
int i=listas[1].getSelectedIndex();
switch(i){ //opcion del menu
case 1:{ canvas = new mostrarfotos(fotos[0]);
canvas.addCommand(exit);
canvas.addCommand(back);
canvas.setCommandListener(this) ;
pantalla.setCurrent(canvas);}
case 0:{canvas = new mostrarfotos(fotos[1]);
canvas.addCommand(exit);
canvas.addCommand(back);
canvas.setCommandListener(this) ;
pantalla.setCurrent(canvas);}
}
}
}else if(d==listas[2]){
System.err.println("Entro en la lista 2: \n");
if(c==List.SELECT_COMMAND){
int i=listas[2].getSelectedIndex();
switch(i){ //opcion del menu
case 1:{ canvas = new mostrarfotos(fotos[3]);
canvas.addCommand(exit);
canvas.addCommand(back);
canvas.setCommandListener(this) ;
pantalla.setCurrent(canvas);}
case 0:{canvas = new mostrarfotos(fotos[2]);
canvas.addCommand(exit);
canvas.addCommand(back);
canvas.setCommandListener(this) ;
pantalla.setCurrent(canvas);}
}
}
}else if(d==listas[3]){
System.err.println("Entro en la lista 3: \n");
if(c==List.SELECT_COMMAND){
int i=listas[3].getSelectedIndex();
switch(i){ //opcion del menu
case 1:{ canvas = new mostrarfotos(fotos[5]);
canvas.addCommand(exit);
canvas.addCommand(back);
canvas.setCommandListener(this) ;
pantalla.setCurrent(canvas);}
case 0:{canvas = new mostrarfotos(fotos[4]);
canvas.addCommand(exit);
canvas.addCommand(back);
canvas.setCommandListener(this) ;
pantalla.setCurrent(canvas);}
}
}
}
if (c == back){ //Selecciono comando “Atrás”
pantalla.setCurrent(listas[0]);
}
}
Where Listas[0] contains the main list, Listas[1] contains "Photos Russia", Listas[2] contains "Photos Spain" and so on.
But it does not work, and I do not know why. Can somebody help me??
|