Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

list component not working

 
david russell
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey guys, anyone have any ideas on this?
my list component isnt selecting. its part of a command listener class, and its used to do an action after a list component has been selected.
the class is shown below:
//listener for all events that take place during midlet life cycle
private class StockCommandListener implements CommandListener {
//this method determines what action to take
public void commandAction(Command c, Displayable d) {
String type = c.getLabel();
// Main command executed, always show Main Menu regardless of which screen is showing
if (type.equals("Main")) {
mainMenu();
//exit command, shut down midlet
} else if (type.equals("Exit")) {
/*try {
destroyApp(true);
}catch (MIDletStateChangeException msce) {
mainMenu();
}*/
getStock();
chooseProduct(true);

//back command, check which screen its on and move
}else if (type.equals("Back")){
if(currentMenu.equals("stockInfo")){
//displayStock();
}
// no command button was pressed but a list selection was made
}else {
List shown = (List) display.getCurrent();
if(currentMenu.equals("Main")){
switch (shown.getSelectedIndex()){
case 0:
chooseProduct(true);

break;

case 1:
//send stock data to servlet
chooseProduct(true);
break;

default:
break;
}

//we now know that its a menu of stock so we have to show the stock info for that particular product
}else {
if(currentMenu.equals("view")){
displayProduct(Products.getString(Products.getSelectedIndex()));
}
}
}
return;
}
}
//end
its probably something daft, im not too good with spotting easy errors.
thanks
dave
[ March 16, 2002: Message edited by: david russell ]
 
Horaci Macias
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please, could you explain what type is currentMenu ? Are you sure that with currentMenu.equals("Main") you are checking what you want?
Also, make sure that you List is created with IMPLICIT argument, otherwise it will not notify events.
I think it'd be better to check to distinguish between select events and command events. (look at MIDP API for details)
Hope it helps,
Horaci Macias
 
david russell
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey,
current menu is just a string that i apply to all menus and forms, it makes it easier to identify to the command listener what part of the applications its working on. for example, after i set up and call the main menu i say currentMenu ="main". im pretty sure that the command listener is checking the main menu. ive seen the code used in other apps(quotesmidlet.java in the code samples on wireless.java.sun.com) so im a little puzzled as to why it doesnt work here.
ill try the list.select command anyway, thanks for the tip!!
dave
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic