Note that there are some explanatory texts on larger screens.

plurals
  1. POonCreateView() method of ViewPager's childFragment not being called
    text
    copied!<p><strong>MainActivity.java</strong></p> <pre><code>public class MainActivity extends SherlockFragmentActivity { static MyListfragment mf; ViewPager mpager; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); mf = new MyListfragment(); ft.add(android.R.id.content,mf).commit(); }} </code></pre> <p><strong>MyListfragment.java</strong></p> <pre><code>public class MyListfragment extends SherlockListFragment { MyDisplayfragment tempFrag; @Override public void onListItemClick(ListView l, View v, int position, long id) { // TODO Auto-generated method stub super.onListItemClick(l, v, position, id); Connector.selection = position; FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction(); if(position==0) { tempFrag=new MyDisplayfragment(); tempFrag.setLayout(R.layout.law); subFragmentAdapter mAdapter = new subFragmentAdapter(getChildFragmentManager()); tempFrag.setViewPagerAdapter(mAdapter); } ft.replace(android.R.id.content,tempFrag); ft.addToBackStack(null); ft.commit(); } @Override public void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); int layout = Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.HONEYCOMB ? android.R.layout.simple_list_item_activated_1 : android.R.layout.simple_list_item_1; setListAdapter(new ArrayAdapter&lt;String&gt;(getActivity(), layout, Connector.list)); }} </code></pre> <p><strong>MyDisplayfragment.java</strong></p> <pre><code>public class MyDisplayfragment extends SherlockFragment { int resource; FragmentPagerAdapter mAdapter; ViewPager v; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub if(Connector.selection==-1) resource=R.layout.displayfragment; return inflater.inflate(resource, container, false); } public void setViewPagerAdapter(FragmentPagerAdapter x) { mAdapter=x; } public void setLayout(int layout) { resource=layout; } @Override public void onViewCreated(View view, Bundle savedInstanceState) { // TODO Auto-generated method stub super.onViewCreated(view, savedInstanceState); ViewPager pager=(ViewPager) view.findViewById(R.id.mpager); pager.setAdapter(mAdapter); }} </code></pre> <p><strong>subFragment.java</strong></p> <pre><code>public final class subFragment extends SherlockFragment { private int layout; public static subFragment newInstance(int content) { subFragment fragment = new subFragment(); fragment.layout=content; return fragment; } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub return inflater.inflate(layout,container,false); }} </code></pre> <p><strong>subFragmentAdapter.java</strong></p> <pre><code>public class subFragmentAdapter extends FragmentPagerAdapter{ int[] LAYOUT={R.layout.cccc,R.layout.aaaa,R.layout.bbb}; private int mCount; public subFragmentAdapter(FragmentManager fm) { super(fm); mCount = LAYOUT.length; } @Override public Fragment getItem(int position) { return subFragment.newInstance(LAYOUT[position]); } @Override public int getCount() { return mCount; } } </code></pre> <p><strong>Connector.java</strong></p> <pre><code>public class Connector { static int selection = -1; static String list[] = { "Law" };} </code></pre> <p>In the above project<br> 1)MyListfragment.java is used for navigation<br> 2)MyDisplayfragment.java is used to display according to selection made in MyListFragment 3)Connector.java is used to communicate between the above two fragments<br> 4)subFragment.java is used to populate Viewpager with Fragments<br> 5)subFragmentAdapter.java is th adapter for Viewpager</p> <p>When i run this project the viewpager seems to be blank and doesnot show any of the child fragments and after debugging i saw that onCreateView() method of subFragment.java is not called. My question is why the onCreateView() method is not being called</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload