Your turn! Please complete this task with your partner.
ButtonFragment.java
public class ButtonFragment extends Fragment
{
@Override
public View onCreateView( LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState )
{
View layout = inflater.inflate( R.layout.buttons,
container,
false );
return layout;
}
}
The XML view doesn't exist, so we'll create a file called buttons.xml
in the src/layout/
folder. We'll add the specifics of the view later.
<?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">
</LinearLayout>
ButtonFragmentTest.java
@RunWith (RobolectricTestRunner.class)
public class ButtonFragmentTest
{
@Test
public void shouldNotBeNull() throws Exception
{
ButtonFragment fragment = new ButtonFragment();
startFragment( fragment);
assertNotNull( fragment );
}
}
Let's add our fragment to main.xml
below the DisplayFragment
.
<fragment
android:id="@+id/buttons_fragment"
android:name="com.mobiquity.calculator.ButtonFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
@Test
public void shouldHaveButtonsFragment() throws Exception
{
assertNotNull( activity.getFragmentManager()
.findFragmentById( R.id.buttons_fragment ) );
}
Make sure to run the tests and then commit your work to your repository.