How do I make an EditText on Android such that the user may not enter a multi-line text, but the display is still multi-line (i.e. there is word-wrap instead of the text going over to the right)?
It's similar to the built-in SMS application where we can't input newline but the text is displayed in multiple lines.
By default all the EditText widgets in Android are multi-lined.
android:windowSoftInputMode="stateAlwaysVisible" -> in manifest File. edittext. requestFocus(); -> in code. This will open soft keyboard on which edit-text has request focus as activity appears.
I would subclass the widget and override the key event handling in order to block the Enter
key:
class MyTextView extends EditText { ... @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode==KeyEvent.KEYCODE_ENTER) { // Just ignore the [Enter] key return true; } // Handle all other keys in the default way return super.onKeyDown(keyCode, event); } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With