ActionBarSherlock: OnOptionsItemSelected doesn't recognize R.id.home

actionbarsherlock, android, android-activity

Solution

just replace this

android.R.id.home

to

R.id.home

and check your code... run it

because

`R.layout.*` are layouts you provide (in res/layout, for example).

`android.R.layout.*` are layouts that ship with the Android SDK.

Problem

I'm using the ActionBarSherlock library and I'm following the exact steps as suggested here and here to enable navigation to the previous screen. My code looks like this: `getSupportActionBar().setDisplayHomeAsUpEnabled(true);` and ``` @Override public boolean onOptionsItemSelected(MenuItem item) { // This callback is used only when mSoloFragment == true (see // onActivityCreated above) switch (item.getItemId()) { case android.R.id.home: // App icon in Action Bar clicked; go up Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Reuse the // existing // instance startActivity(intent); return true; default: return super.onOptionsItemSelected(item); } ``` But R.id.home is not recognized and home shows up in red. :-/ If I use the native actionbar the home declaration takes me to ids.xml file. But here the declaration is not found while I use the ActionBarSherlock Activity. Am I missing something?

Original source

Related problems