First: I am fairly new to android. This project is probably above my pay grade so if I ask a wrong question, at least you understand.
I want to use a TabLayout with ViewPager2 with the views that each page will contain be made of complex fragments. Each page will have the same fragment definition. As far as I can tell at this point, ViewPager2 depends on RecyclerView. I have attempted to use a LinearLayout for each page and I kept getting a fault that referenced the RecyclerView.Adapter.
I create the recyclerView from within another fragment as:
recyclerView = (RecyclerView) mView.findViewById(R.id.recycler_view);
recyclerView.setHasFixedSize(true);
// use a linear layout manager
layoutManager = new LinearLayoutManager(getContext());
recyclerView.setLayoutManager(layoutManager);
List<String> input = new ArrayList<>();
for (int i = 0; i < 5; i++) {
input.add("Test" + i);
}// define an adapter
mAdapter = new SalinasAdapter(input, this);
recyclerView.setAdapter(mAdapter);
and the SalinasAdapter's onCreateViewHolder
public SalinasAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
// create a new view
View v = null;
FragmentManager fm = mFragment.getChildFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
// Add the fragment but do not put it in a container
ft.add(new RowFragment(), Integer.toString(mIndex));
ft.commit();
ft.commitNow();
// Find the fragment from the fragment manager
Fragment foo = fm.findFragmentByTag(Integer.toString(mIndex));
mIndex++;
// Keep track of the index in an ArrayList<String> so they can be removed from the
// FragmentManager when needed.
// ToDo
// Make sure it is mine
if (foo instanceof RowFragment){
v = foo.getView();
}
// Add the view to a ViewHolder
ViewHolder vh = new ViewHolder(v);
return vh;
}
From this I assume that real views are passed to the ViewHolder and it can find all of the elements it needs to set the data correctly.
When done the application shows the five rows for a brief few seconds before it crashes.
I guess I have two questions: Is this the right way to look at this problem? Is there a way to debug, to catch the fault stack trace?