0

For some reason the overflow dots do not appear on my tablet for my master detail application when I select a list item but yet they do on my handset. I'm not sure why is occurring despite using the necessary code. Does anyone there is any code missing or that shouldn't be there?

MainActivity.java

public class MainActivity extends ActionBarActivity {

    private boolean mTwoPane;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        try {
            ViewConfiguration config = ViewConfiguration.get(this);
            Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
            if (menuKeyField != null) {
                menuKeyField.setAccessible(true);
                menuKeyField.setBoolean(config, false);
            }
        }
        catch (Exception e) {
            e.printStackTrace();
        }

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        ActionBar actionBar = getSupportActionBar();
        actionBar.setTitle(getResources().getString(R.string.greeting));

        FragmentMainList newFragment = new FragmentMainList();
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.master_container, newFragment);
        transaction.commit();

        if (findViewById(R.id.detail_container) != null) {
            mTwoPane = true;
        }
    }
}

Activity Class

public class MyProductActivity extends ActionBarActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.my_fragment);

        if (savedInstanceState == null) {
            FragmentProduct newFragment = new FragmentProduct();
            FragmentTransaction transaction = this.getSupportFragmentManager().beginTransaction();
            transaction.replace(R.id.detail_container, newFragment);
            transaction.commit();
        }

        ActionBar actionBar = getSupportActionBar(); 
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.my_menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            final Intent intent = NavUtils.getParentActivityIntent(this);
            intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
            NavUtils.navigateUpTo(this, intent);
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

Fragment Class

public class FragmentProduct extends android.support.v4.app.Fragment {

    public FragmentProduct() {}

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_product, container, false);

        super.onCreate(savedInstanceState);
        setHasOptionsMenu(true);

        return v;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        View v = getView();

        super.onActivityCreated(savedInstanceState);
    }

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        super.onCreateOptionsMenu(menu, inflater);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            final Intent intent = NavUtils.getParentActivityIntent(getActivity());
            intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
            NavUtils.navigateUpTo(getActivity(), intent);
            return true;
        }

        int id = item.getItemId();

        if (id == R.id.action_options) {
        }

        return super.onOptionsItemSelected(item);
    }
}
wbk727
  • 8,017
  • 12
  • 61
  • 125

1 Answers1

1

The dots will be shown only for devices which don't have hardware Menu button. For devices with a hardware Menu button no overflow dots are shown since tapping on the menu button will do the same. For more here

Edit

If for some reason you really want to show it, you can add below code in your Application.onCreate() or main (launcher) activity onCreate()

// force show actionbar 'overflow' button on devices with hardware menu button
try {
    ViewConfiguration config = ViewConfiguration.get(this);
    Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
    if (menuKeyField != null) {
        menuKeyField.setAccessible(true);
        menuKeyField.setBoolean(config, false);
    }
}
catch (Exception e) {
    e.printStackTrace();
}
Dimitar Genov
  • 2,056
  • 13
  • 11
  • Where is `Application.onCreate()`? – wbk727 Jul 07 '15 at 20:17
  • 1
    Your `Application` file if you have such added. If not, add it in your launcher activity `onCreate()` but before calling `setContentView()` – Dimitar Genov Jul 07 '15 at 20:22
  • Hmmmm still not appearing for some reason. MainActivity code is now in my post. – wbk727 Jul 07 '15 at 20:28
  • 1
    `WCBankActivity` is your main activity right? So paste the code in its `onCreate()` method. I see it here working properly in Note 4 (since it has a menu button). If your tablet does **not** have a hardware Menu button and still not seeing the overflow menu - then it is a different case. What manufacturer, brand is the tablet? – Dimitar Genov Jul 07 '15 at 20:34
  • I'm using a tablet emulator as I don't have a real tablet. I think it's best to not to show it and depend on user clicking the menu button on their tablet. Either way I'll still accept your answer. – wbk727 Jul 07 '15 at 20:38
  • 1
    OK, Booted GenyMotion with 2 simulated devices with hardware buttons - Note 3 and XPeria Tablet Z. Both have hardware buttons - both show the overflow menu even so. If you are using Android emulator, maybe you would want to try and stick with [GenyMotion](https://www.genymotion.com/#!/). It is free same as the emulator. – Dimitar Genov Jul 07 '15 at 20:48
  • What about using this for fragments? Remember on tablets, I'm using the master detail hence I'm replacing the detail pane with fragments rather than activities. How can I use that code for my fragment rather than the activity? I want to show different overflow menus based on the fragment that was replaced. – wbk727 Jul 10 '15 at 11:06
  • 1
    Well, it does not matter if you are using activities or fragments. You are using at least one activity (your launcher activity). Add the code in your launcher activity. – Dimitar Genov Jul 10 '15 at 11:34
  • Okay cool. Do you know how to solve this? [Fast scroll large letter thumb preview not appearing](http://stackoverflow.com/questions/31321784/fast-scroll-large-letter-thumb-preview-not-appearing) – wbk727 Jul 10 '15 at 21:03