У меня есть диалог с редактированием текста. Я хочу выполнить действие, когда пользователь нажимает на клавиатуре. Мой код выглядитОбработка «Готово» Событие в клавиатуре не работает
Мой редактировать текст XML выглядит
<EditText
android:id="@+id/commondialog_userinput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:imeOptions="actionDone"
android:selectAllOnFocus="true"
android:inputType="text" />
и слушатель добавляемого
final EditText inputField = (EditText)dialog.findViewById(R.id.commondialog_userinput);
inputField.setInputType(EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
inputField.setText(AndroidGlobalVariables.getDocumentName(), TextView.BufferType.EDITABLE);// No I18N
inputField.setFocusableInTouchMode(true);
inputField.requestFocus();
inputField.selectAll();
inputField.setOnKeyListener(new View.OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// If the event is a key-down event on the "enter" button
if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
Toast.makeText(EditorActivity.getActivity(), inputField.getText(),Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
});