title: Android LazyAdapter for ListView
body: <p>I think I messed up with my Context. Could somebody correct my codes? I cant seems to figure out how to implement Context into my lazyadapter. please take a look at my LOGCAT. Thanks.</p>
  
  <p>AndroidFragment.java</p>
  
  <pre><code>public class AndroidFragment extends SherlockListFragment  implements ActionBar.TabListener{
  
      static final String URL = "https://myxml.xml";
      static final String KEY_SONG = "song";
      static final String KEY_ID = "id";
      static final String KEY_TITLE = "title";
      static final String KEY_CAT_ARTIST = "artistcat";
      static final String KEY_DURATION = "duration";
      static final String KEY_THUMB_URL = "thumb_url";
      static final String KEY_CAT_URL = "cat_url";
      ArrayList&lt;HashMap&lt;String, String&gt;&gt; menuItems;
      ListAdapter adapter;
      Context appContext;
      ListView list;
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
          appContext = inflater.getContext().getApplicationContext();
  
          new loadListView().execute();   
  
      return super.onCreateView(inflater, container, savedInstanceState);
      }
  
  
      public class loadListView extends AsyncTask&lt;Integer, String, String&gt; {
  
          @Override
          protected void onPreExecute() {
              super.onPreExecute();
          }
  
          @Override
          protected String doInBackground(Integer... args) {
              // updating UI from Background Thread
              menuItems = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  
  
              XMLParser parser = new XMLParser();
              String xml = parser.getXmlFromUrl(URL); // getting XML
              Document doc = parser.getDomElement(xml); // getting DOM element
  
              NodeList nl = doc.getElementsByTagName(KEY_SONG);
              // looping through all item nodes &lt;item&gt;
              for (int i = 0; i &lt; nl.getLength(); i++) {
                  // creating new HashMap
                  HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
                  Element e = (Element) nl.item(i);
                  // adding each child node to HashMap key =&gt; value
                  map.put(KEY_ID, parser.getValue(e, KEY_ID));
                  map.put(KEY_TITLE, parser.getValue(e, KEY_TITLE));
                  map.put(KEY_CAT_ARTIST, parser.getValue(e, KEY_CAT_ARTIST));
                  map.put(KEY_DURATION, parser.getValue(e, KEY_DURATION));
                  map.put(KEY_THUMB_URL, parser.getValue(e, KEY_THUMB_URL));
                  map.put(KEY_CAT_URL, parser.getValue(e, KEY_CAT_URL));
  
                  // adding HashList to ArrayList
                  menuItems.add(map);
              }
                  return null;
              }   
  
  
          @Override
          protected void onPostExecute(String args) {
  
  
              adapter=new MainPageLazyAdapter(appContext, menuItems);   
               list.setAdapter(adapter);
           }
      }
  
  
      @Override
      public void onTabSelected(Tab tab, FragmentTransaction ft) {
          ft.add(android.R.id.content, this);
  
          ft.attach(this);
      }
  
      @Override
      public void onTabUnselected(Tab tab, FragmentTransaction ft) {
          ft.detach(this);
      }
  
      @Override
      public void onTabReselected(Tab tab, FragmentTransaction ft) {
      }
  
  }
  </code></pre>
  
  <p>MainPageLazyAdapter.java</p>
  
  <pre><code>public class MainPageLazyAdapter extends BaseAdapter {
  
  private Application activity;
  private ArrayList&lt;HashMap&lt;String, String&gt;&gt; data;
  private static LayoutInflater inflater=null;
  public MainPageImageLoader imageLoader; 
  
  public MainPageLazyAdapter(Context appContext, ArrayList&lt;HashMap&lt;String, String&gt;&gt; d) {
      activity = appContext;
      data=d;
      inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      imageLoader=new MainPageImageLoader(activity);
  }
  </code></pre>
  
  <p>I got this error :</p>
  
  <pre><code>Type mismatch: cannot convert from Context to Application
  </code></pre>