• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Simple question with EditText

gellytabs

Lurker
Dec 5, 2009
1
0
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!
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones