From 243cc13687c837e21016d99af70159d6501f00ed Mon Sep 17 00:00:00 2001 From: =?utf8?q?Reimar=20D=C3=B6ffinger?= Date: Sun, 13 Nov 2016 23:58:42 +0100 Subject: [PATCH] Fix OnItemClick when using keyboard navigation. --- .../android/dictionary/DictionaryActivity.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/com/hughes/android/dictionary/DictionaryActivity.java b/src/com/hughes/android/dictionary/DictionaryActivity.java index 6dc95c6..6366812 100644 --- a/src/com/hughes/android/dictionary/DictionaryActivity.java +++ b/src/com/hughes/android/dictionary/DictionaryActivity.java @@ -421,7 +421,15 @@ public class DictionaryActivity extends ActionBarActivity { } Log.d(LOG, "Loading index " + indexIndex); index = dictionary.indices.get(indexIndex); + getListView().setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); getListView().setEmptyView(findViewById(android.R.id.empty)); + getListView().setOnItemClickListener(new OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int row, long id) { + onListItemClick(getListView(), view, row, id); + } + }); + setListAdapter(new IndexAdapter(index)); // Pre-load the collators. @@ -544,13 +552,6 @@ public class DictionaryActivity extends ActionBarActivity { ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); customSearchView.setLayoutParams(layoutParams); - listView.setOnItemClickListener(new OnItemClickListener() { - @Override - public void onItemClick(AdapterView parent, View view, int row, long id) { - onListItemClick(getListView(), view, row, id); - } - }); - languageButton = new ImageButton(customSearchView.getContext()); languageButton.setId(R.id.languageButton); languageButton.setScaleType(ScaleType.FIT_CENTER); @@ -1569,7 +1570,7 @@ public class DictionaryActivity extends ActionBarActivity { // http://groups.google.com/group/android-developers/browse_thread/thread/3d96af1530a7d62a?pli=1 result.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); result.setClickable(true); - result.setFocusable(true); + result.setFocusable(false); result.setLongClickable(true); // result.setBackgroundResource(android.R.drawable.menuitem_background); @@ -1646,6 +1647,7 @@ public class DictionaryActivity extends ActionBarActivity { } }); } + result.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); return result; } -- 2.43.0