title: EXAMPLE of json with fragment
body: <p>i'm trying to convert my application from activity to fragment 
  my application have listview that load from internet throw JSoN 
  i searched for examples or documentation about json working in fragment 
  or converting activity to fragment on detail  and i couldn't find any useful material </p>
  
  <h1>so any help please :)</h1>
  
  <p>here is an example that i want to converter it from activity to fragment</p>
  
  <pre><code>    public class MainActivity extends Activity {
  
  
  
  
  
  
  
  
      ///////////////////////////
  
  
      private DrawerLayout mDrawerLayout;
      private ListView mDrawerList;
      private ActionBarDrawerToggle mDrawerToggle;
  
      // nav drawer title
      private CharSequence mDrawerTitle;
  
      // used to store app title
      private CharSequence mTitle;
  
      // slide menu items
      private String[] navMenuTitles;
      private TypedArray navMenuIcons;
  
      private ArrayList&lt;NavDrawerItem&gt; navDrawerItems;
      private NavDrawerListAdapter listadapter;
  
      /////////////////////////////////
  
  
  
  
  
      int counter = 0;
  
      // Log tag
      private static final String TAG = MainActivity.class.getSimpleName();
  
      // Movies json url
      private static final String url = "http://api.androidhive.info/json/movies.json";
      private ProgressDialog pDialog;
      private List&lt;Movie&gt; movieList = new ArrayList&lt;Movie&gt;();
      private ListView listView;
      private CustomListAdapter adapter;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
  
  
  
  
          /////////////////////////////////////
  
  
  
          mTitle = mDrawerTitle = getTitle();
  
          // load slide menu items
          navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items);
  
          // nav drawer icons from resources
          navMenuIcons = getResources()
                  .obtainTypedArray(R.array.nav_drawer_icons);
  
          mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
          mDrawerList = (ListView) findViewById(R.id.list_slidermenu);
  
          navDrawerItems = new ArrayList&lt;NavDrawerItem&gt;();
  
          // adding nav drawer items to array
          // Home
          navDrawerItems.add(new NavDrawerItem(navMenuTitles[0], navMenuIcons.getResourceId(0, -1)));
          // Find People
          navDrawerItems.add(new NavDrawerItem(navMenuTitles[1], navMenuIcons.getResourceId(1, -1)));
          // Photos
          navDrawerItems.add(new NavDrawerItem(navMenuTitles[2], navMenuIcons.getResourceId(2, -1)));
          // Communities, Will add a counter here
          navDrawerItems.add(new NavDrawerItem(navMenuTitles[3], navMenuIcons.getResourceId(3, -1), true, "22"));
          // Pages
          navDrawerItems.add(new NavDrawerItem(navMenuTitles[4], navMenuIcons.getResourceId(4, -1)));
          // What's hot, We  will add a counter here
          navDrawerItems.add(new NavDrawerItem(navMenuTitles[5], navMenuIcons.getResourceId(5, -1), true, "50+"));
  
  
          // Recycle the typed array
          navMenuIcons.recycle();
  
          mDrawerList.setOnItemClickListener(new SlideMenuClickListener());
  
          // setting the nav drawer list adapter
          listadapter = new NavDrawerListAdapter(getApplicationContext(),
                  navDrawerItems);
          mDrawerList.setAdapter(listadapter);
  
          // enabling action bar app icon and behaving it as toggle button
          getActionBar().setDisplayHomeAsUpEnabled(true);
          getActionBar().setHomeButtonEnabled(true);
  
          mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
                  R.drawable.ic_drawer, //nav menu toggle icon
                  R.string.app_name, // nav drawer open - description for accessibility
                  R.string.app_name // nav drawer close - description for accessibility
          ) {
              public void onDrawerClosed(View view) {
                  getActionBar().setTitle(mTitle);
                  // calling onPrepareOptionsMenu() to show action bar icons
                  invalidateOptionsMenu();
              }
  
              public void onDrawerOpened(View drawerView) {
                  getActionBar().setTitle(mDrawerTitle);
                  // calling onPrepareOptionsMenu() to hide action bar icons
                  invalidateOptionsMenu();
              }
          };
          mDrawerLayout.setDrawerListener(mDrawerToggle);
  
          if (savedInstanceState == null) {
              // on first time display view for first nav item
              displayView(0);
          }
  
  
          ///////////////////////////////////////
  
  
  
  
  
  
  
  
  
          listView = (ListView) findViewById(R.id.list);
          adapter = new CustomListAdapter(this, movieList);
          listView.setAdapter(adapter);
          listView.setOnScrollListener(new EndlessScrollListener() {
  
              @Override
              public void onLoadMore(int page, int totalItemsCount) {
                  // TODO Auto-generated method stub
                 // new Loadmore().execute();
                  loadList(counter);
              }
          });
          loadList(counter);
  
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }
  
      public void loadList(int i)
      {
          pDialog = new ProgressDialog(this);
          // Showing progress dialog before making http request
          pDialog.setMessage("Loading...");
          pDialog.show();
  
          // changing action bar color
          getActionBar().setBackgroundDrawable(
                  new ColorDrawable(Color.parseColor("#1b1b1b")));
  
          // Creating volley request obj
          JsonArrayRequest movieReq = new JsonArrayRequest(url,
                  new Response.Listener&lt;JSONArray&gt;() {
                      @Override
                      public void onResponse(JSONArray response) {
                          Log.d(TAG, response.toString());
                          hidePDialog();
  
                          int subcounter = counter +3;
                          // Parsing json
                          for (int i = counter; i &lt; (subcounter); i++) {
                              try {
  
                                  JSONObject obj = response.getJSONObject(i);
                                  Movie movie = new Movie();
                                  movie.setTitle(obj.getString("title"));
                                  movie.setThumbnailUrl(obj.getString("image"));
                                  movie.setRating(((Number) obj.get("rating"))
                                          .doubleValue());
                                  movie.setYear(obj.getInt("releaseYear"));
  
                                  // Genre is json array
                                  JSONArray genreArry = obj.getJSONArray("genre");
                                  ArrayList&lt;String&gt; genre = new ArrayList&lt;String&gt;();
                                  for (int j = 0; j &lt; genreArry.length(); j++) {
                                      genre.add((String) genreArry.get(j));
                                  }
                                  movie.setGenre(genre);
  
                                  // adding movie to movies array
                                  movieList.add(movie);
  
                              } catch (JSONException e) {
                                  e.printStackTrace();
                              }
  
                          }
                          counter = counter + 3 ;
                          // notifying list adapter about data changes
                          // so that it renders the list view with updated data
                          adapter.notifyDataSetChanged();
                      }
                  }, new Response.ErrorListener() {
                      @Override
                      public void onErrorResponse(VolleyError error) {
                          VolleyLog.d(TAG, "Error: " + error.getMessage());
                          hidePDialog();
  
                      }
                  });
  
          // Adding request to request queue
          AppController.getInstance().addToRequestQueue(movieReq);
      }
  
      @Override
      public void onDestroy() {
          super.onDestroy();
          hidePDialog();
      }
  
      private void hidePDialog() {
          if (pDialog != null) {
              pDialog.dismiss();
              pDialog = null;
          }
      }
  
  
  
  
  
  
  
  
  
  
      private void displayView(int position) {
          // update the main content by replacing fragments
          Fragment fragment = null;
          switch (position) {
          case 0:
  
              break;
          case 1:
               Intent i = new Intent(MainActivity.this,MainActivity.class);
  
  
                  startActivity(i);
                  finish();
              break;
          case 2:
  
              break;
          case 3:
  
              break;
          case 4:
  
              break;
          case 5:
  
              break;
  
          default:
              break;
          }
  
  
  
              // update selected item and title, then close the drawer
              mDrawerList.setItemChecked(position, true);
              mDrawerList.setSelection(position);
              setTitle(navMenuTitles[position]);
              mDrawerLayout.closeDrawer(mDrawerList);
  
  
      }
  
      @Override
      public void setTitle(CharSequence title) {
          mTitle = title;
          getActionBar().setTitle(mTitle);
      }
  
      /**
       * When using the ActionBarDrawerToggle, you must call it during
       * onPostCreate() and onConfigurationChanged()...
       */
  
      @Override
      protected void onPostCreate(Bundle savedInstanceState) {
          super.onPostCreate(savedInstanceState);
          // Sync the toggle state after onRestoreInstanceState has occurred.
          mDrawerToggle.syncState();
      }
  
      @Override
      public void onConfigurationChanged(Configuration newConfig) {
          super.onConfigurationChanged(newConfig);
          // Pass any configuration change to the drawer toggls
          mDrawerToggle.onConfigurationChanged(newConfig);
      }
  
      private void forceRTLIfSupported()
      {
          if(Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.JELLY_BEAN_MR1){
              getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
          }
      }
  
  
  
  
  
      private class SlideMenuClickListener implements
      ListView.OnItemClickListener {
  @Override
  public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position,
          long id) {
      // display view for selected nav drawer item
      displayView(position);
  }
  }
  
  
  
  
  }
  </code></pre>
  
  <hr>
  
  <pre><code>public class AppController extends Application {
  
      public static final String TAG = AppController.class.getSimpleName();
  
      private RequestQueue mRequestQueue;
      private ImageLoader mImageLoader;
  
      private static AppController mInstance;
  
      @Override
      public void onCreate() {
          super.onCreate();
          mInstance = this;
      }
  
      public static synchronized AppController getInstance() {
          return mInstance;
      }
  
      public RequestQueue getRequestQueue() {
          if (mRequestQueue == null) {
              mRequestQueue = Volley.newRequestQueue(getApplicationContext());
          }
  
          return mRequestQueue;
      }
  
      public ImageLoader getImageLoader() {
          getRequestQueue();
          if (mImageLoader == null) {
              mImageLoader = new ImageLoader(this.mRequestQueue,
                      new LruBitmapCache());
          }
          return this.mImageLoader;
      }
  
      public &lt;T&gt; void addToRequestQueue(Request&lt;T&gt; req, String tag) {
          // set the default tag if tag is empty
          req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
          getRequestQueue().add(req);
      }
  
      public &lt;T&gt; void addToRequestQueue(Request&lt;T&gt; req) {
          req.setTag(TAG);
          getRequestQueue().add(req);
      }
  
      public void cancelPendingRequests(Object tag) {
          if (mRequestQueue != null) {
              mRequestQueue.cancelAll(tag);
          }
      }
  }
  </code></pre>
  
  <p>=================================================================</p>
  
  <pre><code>  public class LruBitmapCache extends LruCache&lt;String, Bitmap&gt; implements
          ImageCache {
      public static int getDefaultLruCacheSize() {
          final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
          final int cacheSize = maxMemory / 8;
  
          return cacheSize;
      }
  
      public LruBitmapCache() {
          this(getDefaultLruCacheSize());
      }
  
      public LruBitmapCache(int sizeInKiloBytes) {
          super(sizeInKiloBytes);
      }
  
      @Override
      protected int sizeOf(String key, Bitmap value) {
          return value.getRowBytes() * value.getHeight() / 1024;
      }
  
      @Override
      public Bitmap getBitmap(String url) {
          return get(url);
      }
  
      @Override
      public void putBitmap(String url, Bitmap bitmap) {
          put(url, bitmap);
      }
  }
  </code></pre>
  
  <hr>
  
  <p>i don't know a lot of fragments so i'm totally lost every time i try to change the code i get lot of errors </p>