I am trying to add a new fragment to my application.
But this fragment is null.
What am I doing wrong?
Fragment launch:
ConvertOptions fragment = (ConvertOptions) getSupportFragmentManager() .findFragmentByTag(Utils.CONVERT_FRAGMENT_TAG); if (fragment != null) { getSupportFragmentManager() .beginTransaction() .add(R.id.container, fragment, Utils.CONVERT_FRAGMENT_TAG) .commit(); }
Fragment Class Code:
public class ConvertOptions extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.convert_options_fragment, null); return view; } }
XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/options_convert_fragment" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:weightSum="1"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New Button" android:id="@+id/button2" android:layout_gravity="center_horizontal" />
java android android-fragments
user1468102
source share