[Android] Prevent NPE when search item is not found
Geoffrey Métais
git at videolan.org
Wed Mar 4 13:27:41 CET 2015
vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Mar 4 13:02:17 2015 +0100| [a466cf51322ca69a780af08b2caeb6c3ed9fa85e] | committer: Geoffrey Métais
Prevent NPE when search item is not found
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=a466cf51322ca69a780af08b2caeb6c3ed9fa85e
---
vlc-android/src/org/videolan/vlc/gui/MainActivity.java | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index fdd1520..96a1293 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -399,9 +399,8 @@ public class MainActivity extends ActionBarActivity implements OnItemClickListen
public void onBackPressed() {
/* Close the menu first */
if(mRootContainer.isDrawerOpen(mSideMenu)) {
- View search = findViewById(R.id.ml_menu_search);
- if (mFocusedPrior != 0 && search != null)
- search.requestFocus();
+ if (mFocusedPrior != 0)
+ requestFocusOnSearch();
mRootContainer.closeDrawer(mSideMenu);
return;
}
@@ -1025,7 +1024,7 @@ public class MainActivity extends ActionBarActivity implements OnItemClickListen
if(current == null || (entry != null && current.getTag().equals(entry.id))) { /* Already selected */
if (mFocusedPrior != 0)
- findViewById(R.id.ml_menu_search).requestFocus();
+ requestFocusOnSearch();
mRootContainer.closeDrawer(mSideMenu);
return;
}
@@ -1051,10 +1050,16 @@ public class MainActivity extends ActionBarActivity implements OnItemClickListen
mSidebarAdapter.setCurrentFragment(mCurrentFragment);
if (mFocusedPrior != 0)
- findViewById(R.id.ml_menu_search).requestFocus();
+ requestFocusOnSearch();
mRootContainer.closeDrawer(mSideMenu);
}else if (entry.attributeID == R.attr.ic_menu_preferences){
startActivityForResult(new Intent(mContext, PreferencesActivity.class), ACTIVITY_RESULT_PREFERENCES);
}
}
+
+ private void requestFocusOnSearch() {
+ View search = findViewById(R.id.ml_menu_search);
+ if (search != null)
+ search.requestFocus();
+ }
}
More information about the Android
mailing list