4this
4this

Reputation: 759

Android - Can't see the menu option at a fragment layout

I've bumped into something I don't understand.

I'm using the next layout XML code -

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <WebView
        android:id="@+id/faq_webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>

As you can see it only contains a WebView.

Now I've created a class as follows:

public class FaqFrag extends Fragment{



public FaqFrag(){}

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);


}

@SuppressLint("SetJavaScriptEnabled")
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    View v = inflater.inflate(R.layout.faq_lay, container, false);
    WebView wv = (WebView) v.findViewById(R.id.faq_webview);
    wv.getSettings().setJavaScriptEnabled(true);
    wv.loadUrl("http://www.something.com");



    return v;
}

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    // TODO Auto-generated method stub
    inflater.inflate(R.menu.faq_menu, menu);
    super.onCreateOptionsMenu(menu, inflater);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

     switch (item.getItemId()) {

     case R.id.send_feedback:

            Intent email = new Intent(Intent.ACTION_SEND);
            email.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"});        

            email.setType("message/rfc822");
            startActivity(Intent.createChooser(email, "Choose an Email client :"));

         return true;

     default:
        return super.onOptionsItemSelected(item);



     }

}

}

Also I've made the next menu xml file -

    <?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

  <item android:id="@+id/send_feedback"
          android:icon="@drawable/send_feedback_ico"
          android:title="@string/send_feedback_menu"
          android:showAsAction="ifRoom"/>

</menu>

Now the weird thing is that when I'm running the app I can't see the menu button at all. I've used this code before at a diffrent fragment and all was fine.

Just to be clear this fragment is shown aftr a click at a Navigation Drawer, so there's an action bar where the menu button should be shown.

Any one have an idea why isn't this working?

Thanks for any kind of help.

Upvotes: 0

Views: 781

Answers (1)

dcow
dcow

Reputation: 7975

Call

setHasOptionsMenu(true);

in onCreate().

Upvotes: 2

Related Questions