hey guys,
i have made a simple mobile form using sun java toolkit.
My problem is that in my form i need to have linked choicegroups or to be more specific when i select something from first choicegroup then a sub choicegroup appears on the form.
I searched the forum and i came to know that i have to use itemstatelistener for this problem. i have used but it doesn't seem to work. i know i'm committing a terrible mistake so if u guys can please look into the coding.
CODING:
public class mobileApp1 extends MIDlet implements CommandListener,ItemStateListener {
private Display display;
private TextField chassisNo,number,cname,add1, add2,tehsil,cusmobile,cuslandline,trancode,chassisn;
public Form form;
private Command submit,cancel,check;
private DateField datein;
private Date date;
private ChoiceGroup ch,sizeChoice,chd;
private static final int DATE= 0;
String datetostring;
MessageConnection clientConn;
private Alert chasalert,datalert,dcodalert,cnamalert,addalert,tehalert,mobalert,mobialert,tranalert,trancalert;
String[] arr = {"ANDHRA PRADESH", "ASSAM", "BIHAR", "CHATTISGARH", "GUJARAT", "HARYANA", "HIMACHAL PRADESH", "JAMMU & KASHMIR", "JHARKHAND", "KARNATAKA", "KERALA", "MADHYA PRADESH", "MAHARASHTRA", "ORISSA", "PUNJAB", "RAJASTHAN", "TAMIL NADU", "UTTAR PRADESH", "UTTARANCHAL", "WEST BENGAL" };
String[] arr1 = {"ADILABAD", "ANANTPUR","BHAGALPUR", "BASTAR", "BHIWANI", "CHITTOR", "CHAPRA", "CHAMBA", "DIBRUGARH", "DARBHANGA", "DANTEWADA", "FARIDABAD", "FATEHABAD", "GANGANAGAR", "GHAZIABAD", "GORAKHPUR", "HYDERABAD URBAN", "HAJIPUR", "HISSAR", "JALANDHAR", "JAIPUR", "MUMBAI", "MOGA", "MUKTSAR", "MADURAI", "MATHURA", "NAGPUR", "NORTH 24 PARGANAS", "PATNA", "PANCHKULA", "PANIPAT", "PATIALA", "ROPAR", "SANGRUR"};
public mobileApp1() {
form = new Form("Mobile Form");
chassisNo = new TextField("Chassis No:", "", 15, TextField.ANY);
chassisn = new TextField("Chassis No:", "", 15, TextField.ANY);
number = new TextField("Dealer Code", "", 4, TextField.NUMERIC);
cname = new TextField("Customer Name:","", 30, TextField.ANY);
add1 = new TextField("Address1:", "", 100, TextField.ANY);
add2 = new TextField("Address2:", "", 100, TextField.ANY);
date = new Date();
datein = new DateField("Installation Date:", DateField.DATE, TimeZone.getTimeZone("GMT"));
tehsil = new TextField("Tehsil:", "", 100, TextField.ANY);
cusmobile = new TextField("Customer Mobile NO.:", "", 11, TextField.NUMERIC);
cuslandline = new TextField("Customer Jandline No.:", "", 11, TextField.NUMERIC);
trancode = new TextField("Transaction Code.:", "", 6, TextField.ANY);
cancel = new Command("Cancel",Command.CANCEL,2);
submit = new Command("Submit",Command.OK, 2);
check = new Command("Check",Command.OK, 2);
datein.setDate(date);
datetostring = date.toString();
}
public void startApp() throws MIDletStateChangeException{
display = Display.getDisplay(this);
form.append(chassisNo);
form.append(datein);
form.append(number);
form.append(cname);
form.append(add1);
form.append(add2);
ChoiceGroup[] ch ={ new ChoiceGroup("Select State:",ChoiceGroup.POPUP,arr,null) };
for (int iter = 0; iter < ch.length; iter++) {
form.append(ch[iter]);
}
ChoiceGroup[] chd ={ new ChoiceGroup("Select DISTRICT:",ChoiceGroup.POPUP,arr1,null) };
for (int iter = 0; iter < chd.length; iter++) {
form.append(chd[iter]);
}
sizeChoice = new ChoiceGroup("Order:", Choice.POPUP);
sizeChoice.append("Small", null);
sizeChoice.append("Medium",null);
sizeChoice.append("Large", null);
form.append(tehsil);
form.append(cusmobile);
form.append(cuslandline);
form.append(trancode);
form.addCommand(submit);
form.addCommand(cancel);
form.addCommand(check);
form.setCommandListener(this);
form.setItemStateListener(this);
display.setCurrent(form);
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {
notifyDestroyed();
}
public void itemStateChanged(Item item) {
if(item == ch) {
if (ch.getSelectedIndex() == 1) {
form.append(sizeChoice);
}
}
}
public void showMsg() {
Thread t = new Thread(){
public void run(){
String n = chassisNo.getString();
String dcode = number.getString();
String cusname = cname.getString();
String addr1 = add1.getString();
String addr2 = add2.getString();
String teh = tehsil.getString();
String cusm = cusmobile.getString();
String cusl = cuslandline.getString();
String tranc = trancode.getString();
String str13 = "AA ";
str13 = (str13 = str13 + n + ";" + dcode + ";" + datetostring + ";" +cusname + ";" + addr1 + ";" + addr2 + ";" + teh + ";" + cusm + ";" + cusl + ";" + tranc).toUpperCase();
try {
clientConn=(MessageConnection)Connector.open("sms://5550000:1234");
}
catch(Exception e) {
Alert conalert = new Alert("Alert");
conalert.setString("Unable to connect to Station because of network problem");
conalert.setTimeout(2000);
display.setCurrent(conalert);
}
try {
TextMessage textmessage = (TextMessage) clientConn.newMessage(MessageConnection.TEXT_MESSAGE);
textmessage.setAddress("sms://+5550000:1234");
textmessage.setPayloadText(str13);
clientConn.send(textmessage);
}
catch(Exception e)
{
Alert messalert=new Alert("Alert","",null,AlertType.INFO);
messalert.setTimeout(1000);
messalert.setString("Unable to send");
display.setCurrent(messalert);
}
}
};
t.start();
}
public void commandAction(Command c, Displayable d) {
String label=c.getLabel();
if(c == cancel) {
destroyApp(true);
} else if(c == check) {
if (trancode.getString().length() < 6)
{ (trancalert = new Alert("Error", "Please enter 6 digit long transaction code.", null, AlertType.INFO)).setTimeout(1000);
display.setCurrent(trancalert,form);
}
}
else if(c == submit) {
showMsg();
}
}
}

Reply With Quote

