Text box question


Last Updated:

  1. Iguy29

    Iguy29 Member This Topic's Starter

    Joined:
    Jun 19, 2010
    Messages:
    5
    Likes Received:
    0
    Hi, I was just working on an app, and I noticed that I could use the Edit Text in the layout to create a place for the user to input text. There is only one problem, how would you access that text and put it into, say a string? Thanks in advance!
     

    Advertisement
  2. Boogs

    Boogs Well-Known Member

    Joined:
    Apr 6, 2010
    Messages:
    85
    Likes Received:
    16
    In your onCreate() method, capture the EditText object, like so:
    Code (Text):
    1. final EditText edit = (EditText)findViewById(R.id.edit_text_name_in_XML_file);
    Then, you can use the methods of the EditText object to get/set its contents, like so:
    Code (Text):
    1. edit.setText("Hello!");
    2. String sayWhat = edit.getText();
    It's that easy!

    --Boogs
     
  3. cp1

    cp1 Well-Known Member

    Joined:
    Apr 30, 2010
    Messages:
    375
    Likes Received:
    35
    Go through the notepad tutorial -- it's got a lot of edit text info.
     

Share This Page

Loading...