Possible Duplicate:
Desigining a Form in j2me
I have created a Form with str 1 and str 2 as StringItem and added them on Form.
Then i have added addCommand() method to str1 and str2 and when I click on Next button it should display an alert as Category 1 when clicked on category 1 and When category 2 when clicked on category 2 StringItem.
Please suggest a solution
What should I write in if loop of Command Action () method so that When I click on str1 it should display Category 1 and when on str2 ... category 2?
Code is below, above question is in comment within commandAction
method
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.StringItem;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class Menu extends MIDlet implements CommandListener {
Command Next ;
Display display;
Form form;
StringItem str1,str2;
public Menu() {
// TODO Auto-generated constructor stub
str1=new StringItem("1. ", "Category 1");
str2=new StringItem("2.", "Category 2");
form=new Form("Menu");
form.append(str1);
form.append(str2);
Next=new Command("Next",Command.SCREEN, 1);
str1.addCommand(Next);
str2.addCommand(Next);
form.addCommand(Next);
form.setCommandListener(this);
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void startApp() throws MIDletStateChangeException {
// TODO Auto-generated method stub
display=Display.getDisplay(this);
display.setCurrent(form);
}
public void commandAction(Command c, Displayable d) {
// TODO Auto-generated method stub
if(c==Next)
{
if(/* What should I write here? */)
{
Alert alert=new Alert(null, "This is ", null, AlertType.INFO);
display.setCurrent(alert, form);
}
}
}
}
The Next command is required only for the Form and is not required for str1 and str2 . In fact you can have a List which comprises of categories . So in your Menu() constructor
and in your commandAction class you can access the categories selected by