I'm trying to have a different menu show up when a fullscreen dialog is shown but it won't appear. Instead, a blank menu appears.
I've tried calling it conditionally from the original activity and I've tried calling it from the dialog view.
Here's the fullscreen Dialog View:
public class MyMainView extends DialogFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NORMAL, R.layout.layout_full_screen_dialog);
setHasOptionsMenu(true);
}
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear();
new MenuInflater(this.getActivity()).inflate(R.menu.add_to_user_library, menu);
//inflater.inflate(R.menu.add_to_user_library, menu);
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View view = inflater.inflate(R.layout.add_to_user_library, container, false);
// view code here
return view;
}
}
Menu XML:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".result.ResultActivity">
<item
android:id="@+id/save"
android:icon="@drawable/ic_check"
android:showAsAction="ifRoom"
android:title="@string/menu_save_library"
tools:ignore="AppCompatResource" />
<item
android:id="@+id/go_back"
android:icon="@drawable/ic_clear"
android:showAsAction="ifRoom"
android:title="@string/menu_save_library"
tools:ignore="AppCompatResource" />
</menu>
From the activity
public final class ResultActivity extends CoreActivity {
public static void startActivityForResult(Activity a, Result r, int requestCode) {
Intent i = new Intent(a, ResultActivity.class);
i.putExtra(EXTRA_RESULT, r);
a.startActivityForResult(i, requestCode);
a.overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
new MenuInflater(this).inflate(R.menu.activity_result, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.case1:
{
Bundle b = new Bundle();
String myString = (String.valueOf(_result.myString));
b.putString("myString", myString);
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT, Locale.US);
String timeStamp = sdf.format(new Date(_result._timestamp));
b.putString("timeStamp", timeStamp);
String myString1 = _result.myString1;
b.putString("myString1", myString1);
//show the dialog
DialogFragment newFragment = new MyMainView();
newFragment.setArguments(b);
newFragment.show(getFragmentManager(),"SaveIt");
return true;
}
case case2:
{
//etc...
Right now, when the dialog shows up but the menu appears right before it loads then becomes blank.
What I see is the following.