The user clicks a button which brings up a fragment dialog that inflates a fragment like this:
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
View view = getActivity().getLayoutInflater().inflate(
R.layout.monday_fragment, null);
builder.setView(view).setTitle("Homework Due Monday")
.setNegativeButton("Dismiss", null);
AlertDialog dialog = builder.create();
dialog.show();
Here is the xml of the layout specified (monday_fragment.xml) where a reference to the fragment to be inflated lies:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
>
<fragment
android:id="@+id/monday_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.bernard.beaconportal.activities.schedule.daydialogfragments.MondayFragment"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
The fragment in the fragment dialog then inflates its own layout in its OnCreateView:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
swipe = inflater.inflate(R.layout.day_homework_fragment, container,
false);
lView = (ListView) swipe.findViewById(R.id.listView1);
progress = (ProgressBar) swipe.findViewById(R.id.progress);
lView.setVisibility(View.GONE);
return swipe;
}
Here is the "day_homework_fragment.xml" layout that is inflated in the fragment:
<?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"
android:layout_gravity="center"
android:background="@color/light_background">
<ProgressBar
android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center" />
<ListView
android:id="@+id/listView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#ffffff"
android:divider="@null"
android:dividerHeight="0dp"
>
</ListView>
<TextView
android:id="@+id/emptyView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="As of now, no homework due this day"
android:padding="30dp"
android:textSize="16sp"/>
</LinearLayout>
Here is the log of the error it throws, I've tried both this post and this post and neither have fixed the issue.
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: FATAL EXCEPTION: main
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: Process: com.bernard.beaconportal.activities, PID: 786
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: android.view.InflateException: Binary XML file line #10: Error inflating class fragment
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Native Method)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:668)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at android.view.LayoutInflater.inflate(<Xposed>)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at com.bernard.beaconportal.activities.schedule.view.MondayView.showDialog(MondayView.java:232)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at com.bernard.beaconportal.activities.schedule.view.MondayView$1.onClick(MondayView.java:174)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at android.view.View.performClick(View.java:4780)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at android.view.View$PerformClick.run(View.java:19867)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:739)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at android.os.Looper.loop(Looper.java:135)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5338)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:917)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:704)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:115)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: Caused by: java.lang.IllegalStateException: Fragment com.bernard.beaconportal.activities.schedule.daydialogfragments.MondayFragment did not create a view.
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2273)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:111)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:278)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at android.support.v4.app.BaseFragmentActivityDonut.onCreateView(BaseFragmentActivityDonut.java:44)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:78)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV7.callActivityOnCreateView(AppCompatDelegateImplV7.java:842)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV11.callActivityOnCreateView(AppCompatDelegateImplV11.java:34)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:830)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:725)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Native Method)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:668)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at android.view.LayoutInflater.inflate(<Xposed>)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at com.bernard.beaconportal.activities.schedule.view.MondayView.showDialog(MondayView.java:232)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at com.bernard.beaconportal.activities.schedule.view.MondayView$1.onClick(MondayView.java:174)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at android.view.View.performClick(View.java:4780)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at android.view.View$PerformClick.run(View.java:19867)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:739)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at android.os.Looper.loop(Looper.java:135)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5338)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:917)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:704)
10-11 01:50:40.657 786-786/com.bernard.beaconportal.activities E/AndroidRuntime: at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:115)
Edit:I just realized that this only started happening after I moved from eclipse to Android Studio. Maybe that has something to do with it? Possibly all the fragment references are messed up?
onCreateView
oronCreate
for your fragment? – Sturrockday_homework_fragment.xml
fragment – Chinchmonday_fragment
layout tomonday_layout
and see what happens – Lakenyalaker