title: Android ListAdapter How to Correct: Cannot make a static reference to the non-static method
body: <p>I'm trying to put some custom list adapters into their own classes to make my app have less redundant code and to make it more manageable.</p>
  
  <p>I call on the different adapter classes thru a conditional statement within a ListFragment. I originally had the adapters in the ListFragment class and this all worked as planed. Now to clean up everything and to get all that code out of the ListFragment, I moved the Adapters out and into their own classes. Since that was done, these methods have to be static so I can call on them but these new classes now containa lot of: </p>
  
  <blockquote>
    <p>Cannot make a static reference to the non-static method
    setListAdapter(ListAdapter) from the type ListFragment</p>
  </blockquote>
  
  <p>Specifically the setListAdapter, setListAdapter, getFragmentManager, and getFragmentManager methods. I don't want a ton of ListView Fragment classes and since a lot of code would be reused, It makes more since to only have one ListFragment and use conditionals to get the correct adapter but I don't know how to fix these new classes so I can use them.</p>
  
  <p>Sorry for the long explanation.  I'll try to only post the relevant code to get the idea to what I am trying to accomplish and for you to guide me.</p>
  
  <p>Can this be done the way I am doing this and how do I correct it?</p>
  
  <p>If there is a better way, please post some code with your explination or code in what needs to be changed within my Adapter Class.</p>
  
  <p>In my fragment's onActivityCreated:</p>
  
  <pre><code>. . .
  
      // Get the string to query from last Fragment and pass it to this
      // Fragment
      Bundle args = this.getArguments();
  
      boolean rawRes = args.getBoolean(KEY_IS_RAW_RES);
      String url = args.getString(KEY_URL);
      int fileName = args.getInt(KEY_RES_FILE);
  
      this.getJsonFile(url, rawRes, fileName);
  
  }
  
  public void getJsonFile(String url, boolean rawRes, int fileName) {
  
      if (rawRes == true) {
          getFromRawRes(fileName);
      } else {
          getFromURL(url);
      }
  }
  
  public void getFromRawRes(int fileName) {
          InputStream file = getResources().openRawResource(fileName);
          JSONParser jParser = new JSONParser();
          JSONArray json = jParser.getJSONFromRes(file);
          ListAdapter_SevenItem.callback(json, context);//&lt;--THIS IS A CALL TO THE ADAPTER!!
      }
  </code></pre>
  
  <p>One of the Adapters:</p>
  
  <pre><code>public class ListAdapter_SevenItem extends ListViewFragment {
  
  . . .
  
  public static void callback(JSONArray json, Context c) {
      if (json != null) {
      // Hashmap for ListView
      . . .
      // create the list item mapping
          String[] from = new String[]{TAG_LABEL, TAG_TITLE, TAG_DISCR, TAG_RES_FILE, TAG_IS_RAW_RES, TAG_CONT_ID};
          int[] to = new int[]{R.id.listLabel, R.id.listTitle, R.id.listDiscription, R.id.listResFile, R.id.listIsRawRes, R.id.listContID};
  
          // Updating parsed JSON data into ListView
          SimpleAdapter adapter = new SimpleAdapter(c, mList, R.layout.list_item, from, to);
          setListAdapter(adapter);
  
          // selecting single ListView item
          final ListView lv = setListAdapter();
  
          // Launching new screen on Selecting Single ListItem
          lv.setOnItemClickListener(new OnItemClickListener() {
  
              public void onItemClick(AdapterView&lt;?&gt; parent, View view, int pos, long id) {
                  MainActivity.mLayout.toggleSidebar();
                  setHasOptionsMenu(true);
  
                  FragmentManager fm = getFragmentManager();
                  final FragmentTransaction lcFT = fm.beginTransaction();
                  lcFT.setCustomAnimations(R.anim.slide_in, R.anim.hyperspace_out, R.anim.hyperspace_in, R.anim.slide_out);
  
                  final Bundle args = new Bundle();
  
                  String resFile = ((TextView) view.findViewById(R.id.listResFile)).getText().toString();
                  int passResFile = getFragmentManager().getIdentifier(resFile, "raw", "com.andaero.app");
                  args.putInt("KEY_RES_FILE", passResFile);
  
                  boolean isRawRes = true;
                  args.putBoolean("KEY_IS_RAW_RES", isRawRes);
  
                  // Delayed to improve animations
                  final Handler handler = new Handler();
                  handler.postDelayed(new Runnable() {
                      public void run() {
                          ListViewFragment lvf = new ListViewFragment();
                          lcFT.replace(R.id.listContainer, lvf).commit();
                          lvf.setArguments(args);
                      }
                  }, 300);
              }
          });
      }
  }
  </code></pre>
  
  <p>}</p>