title: Getting setlistadapter to work
body: <p>I'm working on an android app and I designing the Home layout which which is using fragments for contacts, messages and some other things. So on the contacts fragment I want to display a list of the persons contacts. I can get a listview working under a listactivity class but with this fragmentactivity I can't get it to work. I have an error that says "The method setListAdapter(ListAdapter) is undefined for the type new Runnable(){}" I just don't know what I need to modify to get this working.</p>
  
  <p>Here is what I have done so far.</p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.List;
  import java.util.Locale;
  
  import org.apache.http.NameValuePair;
  import org.apache.http.message.BasicNameValuePair;
  import org.json.JSONArray;
  import org.json.JSONException;
  import org.json.JSONObject;
  
  import android.content.Context;
  import android.content.Intent;
  import android.os.AsyncTask;
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.support.v4.app.FragmentActivity;
  import android.support.v4.app.FragmentManager;
  import android.support.v4.app.FragmentPagerAdapter;
  import android.support.v4.view.ViewPager;
  import android.util.Log;
  import android.view.LayoutInflater;
  import android.view.Menu;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ListAdapter;
  import android.widget.ListView;
  import android.widget.SimpleAdapter;
  import android.widget.TextView;
  
  
  public class FragTest extends FragmentActivity {  
      ArrayList&lt;HashMap&lt;String, String&gt;&gt; productsList;
      JSONParser jsonparser=new JSONParser();
      String userName;
      public static String url_friends="...";
      public static String url_id="...";
  
      /** 
       * The {@link android.support.v4.view.PagerAdapter} that will provide 
       * fragments for each of the sections. We use a 
       * {@link android.support.v4.app.FragmentPagerAdapter} derivative, which 
       * will keep every loaded fragment in memory. If this becomes too memory 
       * intensive, it may be best to switch to a 
       * {@link android.support.v4.app.FragmentStatePagerAdapter}. 
       */  
      SectionsPagerAdapter mSectionsPagerAdapter;  
  
      /** 
       * The {@link ViewPager} that will host the section contents. 
       */  
      ViewPager mViewPager;  
  
      @Override  
      protected void onCreate(Bundle savedInstanceState) {  
          super.onCreate(savedInstanceState);  
          setContentView(R.layout.activity_frag_test);  
  
          Intent intent=getIntent();
          userName=SaveSharedPreference.getUserName(FragTest.this);
          productsList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
          new LoadAllProducts().execute();
          // Create the adapter that will return a fragment for each of the three  
          // primary sections of the app.  
          mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());  
  
          // Set up the ViewPager with the sections adapter.  
          mViewPager = (ViewPager) findViewById(R.id.pager);  
          mViewPager.setAdapter(mSectionsPagerAdapter);  
  
      }  
  
      @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;  
      }  
  
      /** 
       * A {@link FragmentPagerAdapter} that returns a fragment corresponding to 
       * one of the sections/tabs/pages. 
       */  
      public class SectionsPagerAdapter extends FragmentPagerAdapter {  
  
          public SectionsPagerAdapter(FragmentManager fm) {  
              super(fm);  
          }  
  
          @Override  
          public Fragment getItem(int position) {  
              // getItem is called to instantiate the fragment for the given page.  
              // Return a DummySectionFragment (defined as a static inner class  
              // below) with the page number as its lone argument.  
              Fragment fragment = new DummySectionFragment();  
              Bundle args = new Bundle();  
              args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, position + 1);  
              fragment.setArguments(args);  
              return fragment;  
          }  
  
          @Override  
          public int getCount() {  
              // Show 3 total pages.  
              return 3;  
          }  
  
          @Override  
          public CharSequence getPageTitle(int position) {  
              Locale l = Locale.getDefault();  
              switch (position) {  
              case 0:  
                  return getString(R.string.title_section1).toUpperCase(l);  
              case 1:  
                  return getString(R.string.title_section2).toUpperCase(l);  
              case 2:  
                  return getString(R.string.title_section3).toUpperCase(l);  
              }  
              return null;  
          }  
      }  
  
      /** 
       * A dummy fragment representing a section of the app, but that simply 
       * displays dummy text. 
       */  
      public static class DummySectionFragment extends Fragment {  
          /** 
           * The fragment argument representing the section number for this 
           * fragment. 
           */  
          public static final String ARG_SECTION_NUMBER = "section_number";  
  
          public DummySectionFragment() {  
          }  
  
          @Override  
          public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {  
              View rootView = inflater.inflate(R.layout.fragment_main_dummy, container, false);  
              TextView dummyTextView = (TextView) rootView.findViewById(R.id.section_label);
              if(getArguments().getInt(ARG_SECTION_NUMBER)==1){
                  dummyTextView.setText("Contacts");
              }
              if(getArguments().getInt(ARG_SECTION_NUMBER)==2){
                  dummyTextView.setText("Chat");
              }
              if(getArguments().getInt(ARG_SECTION_NUMBER)==3){
                  dummyTextView.setText("Messages");
              }
              //dummyTextView.setText(Integer.toString(getArguments().getInt(ARG_SECTION_NUMBER)));  
              return rootView;  
          }  
      }
  
      class LoadAllProducts extends AsyncTask&lt;String, String, String&gt;{
  
          public LoadAllProducts(/*Context context, View rootView, ArrayList&lt;HashMap&lt;String, String&gt;&gt; llistatEntrades, ListView lv*/){
  
          }
          @Override
          protected String doInBackground(String... params) {
              List&lt;NameValuePair&gt; param=new ArrayList&lt;NameValuePair&gt;();
              param.add(new BasicNameValuePair("username",userName));
              JSONObject json=jsonparser.makeHttpRequest(url_id, "POST", param);
              Log.d("Ids", json.toString());
  
              List&lt;NameValuePair&gt; prm=new ArrayList&lt;NameValuePair&gt;();
              try {
                  prm.add(new BasicNameValuePair("user_id",json.getString("user_id")));
              } catch (JSONException e1) {
                  // TODO Auto-generated catch block
                  e1.printStackTrace();
              }
              prm.add(new BasicNameValuePair("query","friends"));
  
              JSONObject jsn=jsonparser.makeHttpRequest(url_friends, "POST", prm);
              //Log.d("Friends", jsn.toString());
              try {
  
                  JSONArray array = jsn.getJSONArray("options");
  
                  for (int i = 0; i &lt; array.length(); i++) {
                     // Log.i("name", array.getJSONObject(i).getString("name"));
                      JSONObject c = array.getJSONObject(i);
  
                      // Storing each json item in variable
                      String id = c.getString("contact_id");
                      String name = c.getString("name");
                      String picture=c.getString("picture");
                      Log.i("picture_url", picture);
                      // creating new HashMap
                      HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
  
                      // adding each child node to HashMap key =&gt; value
                      map.put("contact_id", id);
                      map.put("name", name);
                      map.put("picture", picture);
  
                      // adding HashList to ArrayList
                      productsList.add(map);
                  }
  
  
  
              } catch (Exception e) {
                  e.printStackTrace();
              }
              return null;
          }
          protected void onPostExecute(String file_url) {
              // dismiss the dialog after getting all products
  
              // updating UI from Background Thread
              runOnUiThread(new Runnable() {
                  public void run() {
  
                      ListAdapter adapter = new SimpleAdapter(
                              FragTest.this, productsList,
                              R.layout.list_item, new String[] { "contact_id","name", "picture"},
                              new int[] { R.id.pid, R.id.name, R.id.profilepicture });
                      // updating listview
                      setListAdapter(adapter);
                  }
              });
  
          }
      }
  
  }  
  </code></pre>