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

Apps Simple question with EditText

Discussion in 'Android Development' started by gellytabs, Dec 5, 2009.

  1. gellytabs

    gellytabs Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Dec 5, 2009

    Dec 5, 2009
    1
    0
    5
    Hello all,

    I have a button that I would like to start a newline in an EditText. I have tried both of the following, but neither will actually insert a newline:

    EditText t = (EditText) findViewById(R.id.codeText);
    String codeText = t.getText().toString();
    codeText += "\n";
    t.setText(codeText);
    t.setSelection(t.getText().toString().length()); //set cursor to end

    OR

    EditText t = (EditText) findViewById(R.id.codeText);
    SpannableStringBuilder t_init = (SpannableStringBuilder) t.getText();
    t_init.append("\n");
    t.setText(t_init);


    Also, setting the EditText property for horizontal scrolling seems to have no effect:

    android:scrollHorizontally="false"

    Any help would be much appreciated. Thanks!
     

    Advertisement

  2. JoshKraker

    JoshKraker Newbie
    Rank:
    None
    Points:
    15
    Posts:
    21
    Joined:
    Dec 3, 2009

    Dec 3, 2009
    21
    0
    15
    Software Engineer, AmTrust Financial Services Inc.
    Bath, OH, USA
    what about codetext += "\r\n"
     

Share This Page

Loading...