I am creating an app which provides chat functionality in it. There is an EditText in the screen, on which I have set OnKeyListener. Whenever user presses the "Enter" key after typing the message, the message is posted on the screen. It works fine. Here is my EditText:
<EditText android:id="@+id/chatMessageField"
android:layout_height="wrap_content" android:layout_width="fill_parent"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_marginRight="5dip" android:layout_marginLeft="5dip"
android:maxLines="2" android:minLines="1" android:scrollbars="vertical"
android:hint="@string/chatMessageHintText" android:textColorHint="#3b64a8">
</EditText>
The problem is when user wants to go to new line before the EditText wraps the text and goes to new line. Now if user wants to go to new line and presses "Enter" key, the message is sent.
In some chat messangers , I have seen that pressing "Shift+Enter"(or any other key-combination) simultaneously takes the user to new line. How can we detect "Shift+Enter"(or any other key-combination) keys pressed simultaneously in Android? Is there any way to achieve this functionality in Android?
Just try for this... It may help.
Set the input of EditText as
youredittext.setInputType(EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE);
Then add:
android:singleLine="false"
or
youredittext.setSingleLine(false);
Also go Click Here
In your OnKeyListener
method, use check for Enter
and Shift Enter
and provide separate functionality of Send
and New Line
respectively.
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