1. Check out our companion app, Forums for Android! Download from Google Play

Text box question

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

  1. Iguy29

    Iguy29 Member
    Thread Starter
    5

    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
    18

    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 Well-Known Member
    53

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

Share This Page

Loading...