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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Contributor
alpachino
Posts: 22
Registered: ‎03-23-2011
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);
		}

 

Please use plain text.
Administrator
MSohm
Posts: 12,957
Registered: ‎07-09-2008
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.
Found a bug? Report it using the Issue Tracker
Please use plain text.
Contributor
alpachino
Posts: 22
Registered: ‎03-23-2011
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;
	}

}

 

Please use plain text.
Trusted Contributor
hardikhamar
Posts: 159
Registered: ‎02-17-2011

Re: getText()

do u show me ur whole code?

Please use plain text.
Developer
simon_hain
Posts: 13,796
Registered: ‎07-29-2008
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
Please use plain text.
Developer
welsenKiriono
Posts: 202
Registered: ‎04-19-2011
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

Please use plain text.
Trusted Contributor
hardikhamar
Posts: 159
Registered: ‎02-17-2011

Re: getText()

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

Please use plain text.
Contributor
alpachino
Posts: 22
Registered: ‎03-23-2011
My Carrier: Student

Re: getText()

Thanks is working :Phone:

Please use plain text.