Kaidul

Parent Fragment

Aug 13th, 2013
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.37 KB | None | 0 0
  1. package me.kaidul.uhunt;
  2.  
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.io.InputStreamReader;
  6. import java.lang.reflect.Field;
  7. import java.util.ArrayList;
  8. import java.util.List;
  9.  
  10. import me.kaidul.uhunt.ChaptersListFragment.OnChapterSelectListener;
  11. import me.kaidul.uhunt.SubChaptersListFragment.OnSubChapterSelectListener;
  12. import me.kaidul.uhunt.SubSubChaptersListFragment.OnSubSubChapterSelectListener;
  13.  
  14. import com.devspark.progressfragment.SherlockProgressFragment;
  15. import com.google.gson.stream.JsonReader;
  16.  
  17. import android.support.v4.app.Fragment;
  18. import android.support.v4.app.FragmentTransaction;
  19. import android.os.AsyncTask;
  20. import android.os.Bundle;
  21. import android.view.LayoutInflater;
  22. import android.view.View;
  23. import android.view.ViewGroup;
  24.  
  25. public class CompetitiveProgramming extends SherlockProgressFragment implements
  26.         OnChapterSelectListener, OnSubChapterSelectListener, OnSubSubChapterSelectListener {
  27.  
  28.     View mContentView;
  29.     static public List<Chapter> chapterList = new ArrayList<Chapter>();
  30.  
  31.     @Override
  32.     public View onCreateView(LayoutInflater inflater, ViewGroup container,
  33.             Bundle savedInstanceState) {
  34.         mContentView = inflater.inflate(
  35.                 R.layout.competitive_programming_exercise, container, false);
  36.         return super.onCreateView(inflater, container, savedInstanceState);
  37.     }
  38.  
  39.     @Override
  40.     public void onActivityCreated(Bundle savedInstanceState) {
  41.         super.onActivityCreated(savedInstanceState);
  42.         setContentView(mContentView);
  43.         setContentShown(false);
  44.         new ProcessTask().execute();
  45.     }
  46.  
  47.     @Override
  48.     public void onDetach() {
  49.         super.onDetach();
  50.  
  51.         try {
  52.             Field childFragmentManager = Fragment.class
  53.                     .getDeclaredField("mChildFragmentManager");
  54.             childFragmentManager.setAccessible(true);
  55.             childFragmentManager.set(this, null);
  56.  
  57.         } catch (NoSuchFieldException e) {
  58.             throw new RuntimeException(e);
  59.         } catch (IllegalAccessException e) {
  60.             throw new RuntimeException(e);
  61.         }
  62.     }
  63.  
  64.     protected class ProcessTask extends AsyncTask<Void, Void, Void> {
  65.  
  66.         @Override
  67.         protected Void doInBackground(Void... params) {
  68.             // other stuffs
  69.             return null;
  70.         }
  71.  
  72.         @Override
  73.         protected void onPostExecute(Void result) {
  74.             super.onPostExecute(result);
  75.             Fragment chapterFragment = new ChaptersListFragment();
  76.             Fragment subChapterFragment = new SubChaptersListFragment();
  77.             Fragment subSubChapterFragment = new SubSubChaptersListFragment();
  78.             FragmentTransaction transaction = getChildFragmentManager()
  79.                     .beginTransaction();
  80.             transaction.add(R.id.category_fragment, chapterFragment);
  81.             transaction.add(R.id.sub_category_fragment, subChapterFragment);
  82.             transaction.add(R.id.sub_sub_category_fragment,
  83.                     subSubChapterFragment);
  84.             transaction.commit();
  85.             setContentShown(true);
  86.         }
  87.  
  88.     }
  89.  
  90.     @Override
  91.     public void onChapterSelected(int position) {
  92.         SubChaptersListFragment subChapterFrag = new SubChaptersListFragment();
  93.         if ( subChapterFrag != null) {
  94.             subChapterFrag.updateList(position);
  95.         } else {
  96.            
  97.         }
  98.  
  99.     }
  100.  
  101.     @Override
  102.     public void onSubChapterSelected(int prev, int position) {
  103.         SubSubChaptersListFragment subSubChapterFrag = new SubSubChaptersListFragment();
  104.         if (subSubChapterFrag != null) {
  105.             subSubChapterFrag.updateList(prev, position);
  106.         } else {
  107.             // nothing now
  108.         }
  109.     }
  110.  
  111.     @Override
  112.     public void onSubSubChapterSelected(int prev, int nextPrev, int position) {
  113.     }
  114.  
  115. }
Advertisement
Add Comment
Please, Sign In to add comment