7

At the moment it is main activity but I want to change it to the Categories activity. Is this where the problem lies?

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        // This ID represents the Home or Up button. In the case of this
        // activity, the Up button is shown. Use NavUtils to allow users
        // to navigate up one level in the application structure. For
        // more details, see the Navigation pattern on Android Design:
        //
        // http://developer.android.com/design/patterns/navigation.html#up-vs-back
        //
        NavUtils.navigateUpFromSameTask(this);
        return true;
    }
    return super.onOptionsItemSelected(item);
Stephan Celis
  • 2,492
  • 5
  • 23
  • 38
user2229066
  • 143
  • 3
  • 13

2 Answers2

14

Go to AndroidManifest.xml, find your Sport activity and add this code

<activity android:name="Sport" >
    <meta-data
       android:name="android.support.PARENT_ACTIVITY"
       android:value="PARENT_ACTIVITY_PATH" />
</activity>

Substitute PARENT_ACTIVITY_PATH with the name of your parent activity adding also your package name (e.g. com.example.Categories).

Mangusto
  • 1,505
  • 1
  • 13
  • 29
0

Going off @Mangusto. After adding the parent activity path to your AndroidManifest add this line in the onCreate method of your Sport activity getSupportActionBar().setDisplayHomeAsUpEnabled(true);

Raman Shrivastava
  • 2,923
  • 15
  • 26
myEdu
  • 1
  • 2