1. Download our Official Android App: Forums for Android!

Apps Text box question

Discussion in 'Android Development' started by Iguy29, Jun 19, 2010.

  1. Iguy29

    Iguy29 Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Jun 19, 2010

    Jun 19, 2010
    5
    0
    5
    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
    Rank:
    None
    Points:
    18
    Posts:
    85
    Joined:
    Apr 6, 2010

    Apr 6, 2010
    85
    16
    18
    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 Android Enthusiast
    Rank:
    None
    Points:
    53
    Posts:
    375
    Joined:
    Apr 30, 2010

    Apr 30, 2010
    375
    35
    53
    Go through the notepad tutorial -- it's got a lot of edit text info.
     

Share This Page

Loading...