Edit: Hey guys I have deleted everything because I finally found the answer to my question (basically how to use a scrollview inside ViewPager inside a fragment). Here is my code for everything. I am a total noob so I don't really understand what is going on in my code but here it is:
Here is my pager adapter to make fragments go inside ViewPager(I think that is what happens) I took this code from online from CommonsGuy
import android.app.Fragment;
import android.app.FragmentManager;
import android.support.v13.app.FragmentPagerAdapter;
import java.util.List;
public class PagerAdapter extends FragmentPagerAdapter {
private List < Fragment > fragments;
public PagerAdapter(FragmentManager fm, List < Fragment > fragments) {
super(fm);
this.fragments = fragments;
}
@Override
public Fragment getItem(int i) {
return fragments.get(i);
}
@Override
public int getCount() {
return fragments.size();
}
}
Here is my code for the fragment that I will put the ViewPager on
public class RecipeFragment extends Fragment {
public RecipeFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_recipe, container, false);
List < Fragment > fragments = new Vector < > ();
fragments.add(Fragment.instantiate(getActivity(), RecipeOverview.class.getName()));
fragments.add(Fragment.instantiate(getActivity(), RecipeIngredients.class.getName()));
fragments.add(Fragment.instantiate(getActivity(), RecipeProcedures.class.getName()));
PagerAdapter adapter = new PagerAdapter(getChildFragmentManager(), fragments);
ViewPager pager = (ViewPager) view.findViewById(R.id.pager);
pager.setAdapter(adapter);
return (view);
}
}
And below are the xml
files for RecipeFragment
and the different fragments
shown in the ViewPager
respectively
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v4.view.ViewPager>
Layout for mini fragments inside ViewPager. And the .java mini fragment file is just a normal fragment file. I also used nestedScrollView because scrollview say i am stupid person and not working properly.
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".RecipeOverview">
<android.support.v4.widget.NestedScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="10dp">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:text="Ingredients"
android:textStyle="bold"/>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Some Button" />
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Some Button" />
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Some Button" />
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Some Button" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:text="Random Text"
android:textStyle="bold"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:text="Fragment1"
android:textStyle="bold"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:text="Random Text"
android:textStyle="bold"/>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Some Button" />
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Some Button" />
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Some Button" />
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Some Button" />
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Some Button" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:text="Ingredients"
android:textStyle="bold"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:text="Ingredients"
android:textStyle="bold"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:text="Ingredients"
android:textStyle="bold"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:text="Ingredients"
android:textStyle="bold"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:text="Ingredients"
android:textStyle="bold"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.constraint.ConstraintLayout>