Skip to content

Commit c90cc83

Browse files
committed
Correctly fix #57
Previous attempt didn't work out in the end. SoftKeyboard in fragments seems to be bugged. Signed-off-by: Aron Heinecke <aron.heinecke@t-online.de>
1 parent 42130ec commit c90cc83

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

app/src/main/java/vocabletrainer/heinecke/aron/vocabletrainer/activity/EditorActivity.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,6 @@ private void saveEdit() {
248248
adapter.notifyDataSetChanged();
249249
if(!isExisting) {
250250
addEntry();
251-
} else {
252-
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
253-
inputMethodManager.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
254251
}
255252
}
256253

@@ -379,11 +376,11 @@ private synchronized void showEntryEditDialog(final VEntry entry, final int posi
379376
private void setEditorDialogActions(){
380377
editorDialog.setOkAction(e -> {
381378
saveEdit();
382-
Log.d(TAG,"edited");
383379
return null;
384380
});
385381
editorDialog.setCancelAction(e -> {
386-
Log.d(TAG,"canceled");
382+
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
383+
inputMethodManager.toggleSoftInput(0, 0);
387384
return null;
388385
});
389386
}

app/src/main/java/vocabletrainer/heinecke/aron/vocabletrainer/dialog/VEntryEditorDialog.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,10 @@ public void setCancelAction(Function<Void,VEntry> cancelAction) {
8484
public void onResume() {
8585
super.onResume();
8686
if(focusableEditText != null) {
87+
focusableEditText.clearFocus();
8788
focusableEditText.requestFocus();
88-
InputMethodManager imm = (InputMethodManager) requireActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
89-
imm.showSoftInput(focusableEditText, InputMethodManager.SHOW_FORCED);
90-
InputMethodManager inputMethodManager = (InputMethodManager) requireActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
91-
inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
89+
InputMethodManager inputMethodManager = (InputMethodManager) requireContext().getSystemService(Context.INPUT_METHOD_SERVICE);
90+
inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
9291
}
9392
}
9493

@@ -294,12 +293,9 @@ private View generateMeaning(final String meaning, final String hint,int image,
294293
text.setSingleLine();
295294

296295
if(focus) {
297-
Log.d(TAG,"requesting focus");
298-
layout.requestFocus();
299-
InputMethodManager imm = (InputMethodManager) requireActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
300-
imm.showSoftInput(text, InputMethodManager.SHOW_FORCED);
301-
InputMethodManager inputMethodManager = (InputMethodManager) requireActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
302-
inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
296+
Log.d(TAG,"setting focus element");
297+
focusableEditText = text;
298+
focusableEditText.requestFocus();
303299
}
304300

305301
layout.setHint(hint);

0 commit comments

Comments
 (0)