?
Solved

How to retrieve the value from dialog input field?

Posted on 2010-11-20
12
Medium Priority
?
333 Views
Last Modified: 2012-05-10
I am creating a dialog with the input text allow using to fill in the text with 2 button ok and exit which to continue the next process. But i dunno how to retrieve the value.. what syntax?
i will pose u the dialog code, I done the code already, i think it can work fine, just dunno where and which part to get the value.
hopefully someone can check for me.. how to get the value which user key in the text.
looking for solution with the syntax, i think it is just a simple syntax...


final class TestDialog extends Dialog{

    private EditField userNameField;
    private ButtonField okButton;
    private ButtonField cancelButton;

    public TestDialog(String choices[],int values[]){
        super("Enter a username", choices,values,Dialog.OK, Bitmap.getPredefinedBitmap(Bitmap.QUESTION), Dialog.GLOBAL_STATUS);
        userNameField = new EditField("User Name: ", "", 50, EditField.EDITABLE | EditField.FILTER_FILENAME); 
        net.rim.device.api.ui.Manager delegate = getDelegate();
        if( delegate instanceof DialogFieldManager){
            DialogFieldManager dfm = (DialogFieldManager)delegate;
            net.rim.device.api.ui.Manager manager =dfm.getCustomManager();
            if( manager != null ){
                manager.insert(userNameField, 0);              
              
            }
        }
       
    }    

   ( public String getUsernameFromField(){
    	Dialog.alert("testing111"+userNameField.getText());
    	return userNameField.getText();
    }

}



final class TestScreen extends MainScreen
{
    public TestScreen userNameField;
	private Dialog diag;
   

    public TestScreen()
    {
    	String choices[] = {"Ok","Cancel"};
        int values[] = {Dialog.OK,Dialog.CANCEL};
       
        //int values[] = {0,Dialog.OK,Dialog.CANCEL};
        
         diag = new TestDialog(choices,values);
        
        UiApplication.getUiApplication().invokeLater(new Runnable()
        {
            public void run()
            {
                int iResponse = diag.doModal();

                if(iResponse == Dialog.OK)
                {
                    //return;
                	//Dialog.alert("testing"+diag);
                	System.out.println(userNameField);
                }
                else
                {
                    System.exit(0);
                	                }               }
        });          
    }
}

Open in new window

0
Comment
Question by:gagajanice
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
12 Comments
 
LVL 92

Expert Comment

by:objects
ID: 34181878
your getUsernameFromField() method will return the inputted value, you'd just call it by the look of it
0
 

Author Comment

by:gagajanice
ID: 34181894
how to print it out? where it will return too? coz i am newbie in OO concept... quit complicated for me.... can i show u my whole program? then u tell me which i can get the value?
0
 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 34181934
                     System.out.println(diag.getUsernameFromField());
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

Author Comment

by:gagajanice
ID: 34181950
i try to add    System.out.println(diag.getUsernameFromField());

but still got the error, i show u the capture screen
error.JPG
0
 
LVL 92

Assisted Solution

by:objects
objects earned 2000 total points
ID: 34181977
>       private Dialog diag;


change that to:


      private TestDialog diag;
0
 

Author Comment

by:gagajanice
ID: 34181996
Thank you, it can display from the dialog,alert, i can see the value...
i got another question is about how to retrieve this value in other class?
coz i create class for dialog screen for user enter the text, after user click "Continue" button, it should be continue at other class, so how am i get diag.getUsernameFromField(); in the class?

coz i need this input field user for generate the file name....
0
 

Author Comment

by:gagajanice
ID: 34182006
I will sure u the class which to call the dialog class...
in the "final class CameraScreen extends MainScreen"

how to retrieve the diag.getUsernameFromField(); ?

Thank you...
final class CameraScreen extends MainScreen 
{
    /** The camera's video controller */
    private VideoControl _videoControl;

    /** The field containing the feed from the camera */
    private Field _videoField;
    
    private static String _prefilename;
    private static String _UIflag;
    private static TestScreen _rrr;
    
    private int _indexOfEncoding = 0;
    private EditField userNameField;

    /**
     * Constructor. Initializes the camera and creates the UI.
     */
   
    public CameraScreen()
    {
    	

    	if(_UIflag != "OK")
    	{
    

            TestScreen testScreen = new TestScreen();   //<---- call the class to generate dialog
            pushScreen( testScreen );
            
        	
           
        	setTitle("Camera Demo");
        	initializeCamera();       
            if(_videoField != null)
            {
               createUI();
               addMenuItem(_encodingMenuItem);
  
            }
            else
            {
               add( new RichTextField( "Error connecting to camera." ) );
            }
 
    	}
    	else
    	{
    		setTitle("Camera Demo");
        	initializeCamera();       
            if(_videoField != null)
            {
               createUI();
               addMenuItem(_encodingMenuItem);
  
            }
            else
            {
               add( new RichTextField( "Error connecting to camera." ) );
            }	
    		
    	}
    
    
    
    }



private void pushScreen(TestScreen testScreen) {
		
	}
}

Open in new window

0
 
LVL 92

Assisted Solution

by:objects
objects earned 2000 total points
ID: 34182017
add a new method to TestScreen class

public String getUsername() {
   return diag.getUsernameFromField();
}
0
 

Author Comment

by:gagajanice
ID: 34182041
Thankx again, i already added new method in TestScreen class

then, at another class is what syntax then i can get the value?
0
 
LVL 92

Assisted Solution

by:objects
objects earned 2000 total points
ID: 34182068
String username = testScreen.getUsername();
0
 

Author Comment

by:gagajanice
ID: 34182092
After i pass the syntax, i got the error...

here is the capture screen and also the code which from CameraScreen class ( the class which to get the value)
final class CameraScreen extends MainScreen 
{
    /** The camera's video controller */
    private VideoControl _videoControl;

    /** The field containing the feed from the camera */
    private Field _videoField;
    
    private static String _prefilename;
    private static String _UIflag;
    private static TestScreen _rrr;
    
    private int _indexOfEncoding = 0;
    private EditField userNameField;
    private TestScreen userdiag;
    private TestDialog diag;

 private void createImageScreen( byte[] raw )
    {    
    	
    	String filename = TestScreen.getUsername();
    	Dialog.alert("Testing123 "+filename);
    	ImageScreen imageScreen = new ImageScreen( raw );
        
        // Push this screen to display it to the user
        UiApplication.getUiApplication().pushScreen( imageScreen );
    }

Open in new window

error1.JPG
0
 

Author Comment

by:gagajanice
ID: 34182127
Thankx objects...
can work already!!! many thankx~~~

i change it to static..
private static TestDialog diag;
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month11 days, 6 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question