06-20-2011 06:06 AM
I want to retrieve the values that I typed for id and password.
With button is working
ButtonField valider = new ButtonField("Valider");
add(valider);
valider.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
id = user.getText();
mp = pwd.getText();
System.out.println(“-—testid--” + id);
System.out.println(“-—testmp--” + mp);
}
});But when I want to retrieve via MenuItem I have had a red cross for getText method.
MenuItem Item1 = new MenuItem("Valider", 0, 0) {
public void run() {
id= user.getText();
mp= pwd.getText();
System.out.println("----testid----" + id);
System.out.println("----testmp----" + mp);
}
};
protected void makeMenu(Menu menu, int instance) {
menu.add(Item1);
super.makeMenu(menu, instance);
}
Solved! Go to Solution.
06-22-2011 02:38 PM
Where are user and pwd defined? They could be out of scope of your MenuItem.
06-23-2011 04:54 AM
In fact I have already tested it. Certainly I don’t have red cross but isn’t not working also.
Ps: When I test with System.out.println() I don’t get back not even null.
Code inside of scope (constructor)
public class idclass extends MainScreen {
public static String id;
public static String mp;
public idclass() throws IOException
{
super();
LabelField title = new LabelField("id",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
final EditField user = new EditField("Login :", "", 15,
EditField.FILTER_DEFAULT);
add(log);
final PasswordEditField pwd = new PasswordEditField("Password :", "");
add(pwd);
id = user.getText();
system.out.println("----testid-----" + id);
mp = pwd.getText();
system.out.println("----testmp-----" + mp)
}
public boolean onClose() {
Dialog.alert("Goodbye!");
System.exit(0);
return true;
}
}
06-23-2011 05:17 AM
do u show me ur whole code?
06-23-2011 05:32 AM
06-23-2011 05:48 AM
try to declare EditField user and PasswordEditField pw in global
public class idclass extends MainScreen {
public static String id;
public static String mp;
private EditField user;
private PasswordEditField pw;then you can instance this field in constructor, like
public idclass()
{
user = new EditField("Username : ", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
pw = new PasswordEditField("Password :", "");
add(user);
add(pw);then, you can use menu for getting the content of user and pw
06-23-2011 08:23 AM
if u write menuItem In constructor then put it outside but in class and make title and user globally.
06-23-2011 08:31 AM
Thanks is working ![]()