Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Posts: 22
Registered: ‎03-23-2011
My Device: torch
My Carrier: Student
Accepted Solution

getText()

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);
		}

 

BlackBerry Development Advisor
Posts: 15,723
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: getText()

Where are user and pwd defined?  They could be out of scope of your MenuItem.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Contributor
Posts: 22
Registered: ‎03-23-2011
My Device: torch
My Carrier: Student

Re: getText()

 

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;
	}

}

 

Trusted Contributor
Posts: 159
Registered: ‎02-17-2011
My Device: Not Specified

Re: getText()

do u show me ur whole code?

Developer
Posts: 16,992
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: getText()

your fields are locally defined in the constructor.
define them in the class itself (below your static strings)
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Highlighted
Developer
Posts: 202
Registered: ‎04-19-2011
My Device: Blackberry Bold 9780
My Carrier: TAM

Re: getText()

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

Trusted Contributor
Posts: 159
Registered: ‎02-17-2011
My Device: Not Specified

Re: getText()

if u write menuItem In constructor then put it outside but in class and make title and user globally.

Contributor
Posts: 22
Registered: ‎03-23-2011
My Device: torch
My Carrier: Student

Re: getText()

Thanks is working