我陷入一个问题,当我在xml中使用inputtype作为textmultiline和在edittext中使用imeiOptions作为KEYCODE_ENTER时,我的setOnEditorActionListener无法正常工作,但是如果我将inputtype更改为text则可以正常工作,我无法理解为什么这是为什么无法使用textMultiline。
我在xml中定义的Edittext是:
<EditText
android:id="@+id/etremarks"
android:layout_width="match_parent"
android:layout_height="@dimen/_200sdp"
android:background="@drawable/shape_edittext_pink_border"
android:fontFamily="@font/share"
android:gravity="top"
android:hint="Enter Message"
android:inputType="textMultiLine"
android:padding="5dp"
android:textColor="#000000" />
and my code for edittext in java file is-:
etremarks.addTextChangedListener(mTextEditorWatcher);
etremarks.setImeOptions(KeyEvent.KEYCODE_ENTER);
etremarks.setOnEditorActionListener(new TextView.OnEditorActionListener()
{
@Override
public boolean onEditorAction(TextView v, int actionId,
KeyEvent event)
{
boolean handled = false;
if (actionId == KeyEvent.KEYCODE_ENTER)
{
// Handle pressing "Enter" key here
Toast.makeText(SendBulkSmsToClients.this, etremarks.getText(), Toast.LENGTH_SHORT).show();
handled = true;
}
return handled;
}
});
请分享您对这个问题的宝贵意见
谢谢
最佳答案
添加此行android:imeOptions="actionSend"
并在代码中,如下所示处理
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_SEND) {
sendMessage();
handled = true;
}
return handled;
}
关于java - setOnEditorActionListener()方法不适用于输入类型textMultiline以及键盘中的Enter按钮,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49979288/