title: Executing Async tasks in fragments
body: <p>I am attempting to execute an async task in a fragment after converting my activities into fragments. When I call my async task from the activity I have to pass 'this' with it in order to allow the async task to change text and things after it receives the information. I am a bit confused on how to do this all with fragments. Here is what I got so far:</p>
  
  <p>I execute the asynck task with:</p>
  
  <pre><code>new GetYourTopTasteBeers(this).execute(url);
  </code></pre>
  
  <p>the code for the async task is:</p>
  
  <pre><code>public class GetYourTopTasteBeers extends AsyncTask&lt;String, Void, String&gt; {
  
      Context c;
      private ProgressDialog Dialog;
  
      public GetYourTopTasteBeers (Context context)
      {
          c = context;
          Dialog = new ProgressDialog(c);
      }
  
      @Override
      protected String doInBackground(String... arg0) {
          // TODO Auto-generated method stub
          return readJSONFeed(arg0[0]);
      }
  
      protected void onPreExecute() {
          Dialog.setMessage("Getting beers");
  
          Dialog.setTitle("Loading");
          Dialog.setCancelable(false);
          Dialog.show();
      }
  
      protected void onPostExecute(String result){
          //decode json here
          try{
              JSONArray jsonArray = new JSONArray(result);
  
  
              //acces listview
              ListView lv = (ListView) ((Activity) c).findViewById(R.id.topTasteBeers);
  
              //make array list for beer
              final List&lt;ShortBeerInfo&gt; tasteList = new ArrayList&lt;ShortBeerInfo&gt;();
  
  
  
              for(int i = 0; i &lt; jsonArray.length(); i++) {
  
                  String beer = jsonArray.getJSONObject(i).getString("beer");
                  String rate = jsonArray.getJSONObject(i).getString("rate");
                  String beerID = jsonArray.getJSONObject(i).getString("id");
                  String breweryID = jsonArray.getJSONObject(i).getString("breweryID");
  
  
                  int count = i + 1;
  
                  beer = count + ". " + beer;
  
  
                  //create object
                  ShortBeerInfo tempTaste = new ShortBeerInfo(beer, rate, beerID , breweryID);
  
                  //add to arraylist
                  tasteList.add(tempTaste);
  
  
                  //add items to listview
                  ShortBeerInfoAdapter adapter1 = new ShortBeerInfoAdapter(c ,R.layout.brewer_stats_listview, tasteList);
                  lv.setAdapter(adapter1);
  
                  //set up clicks
                  lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                      @Override
                      public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1,
                                              int arg2, long arg3) {
                          ShortBeerInfo o=(ShortBeerInfo)arg0.getItemAtPosition(arg2);
  
                          String tempID = o.id;
                          String tempBrewID = o.brewery;
  
                          Toast toast = Toast.makeText(c, tempID, Toast.LENGTH_SHORT);
                          toast.show();
  
                          //todo: change fragment to beer page
  
                          Intent myIntent = new Intent(c, BeerPage2.class);
                          myIntent.putExtra("id", tempID);
                          myIntent.putExtra("breweryID", tempBrewID);
                          c.startActivity(myIntent);
  
  
                      }
                  });
  
  
  
  
              }
  
          }
          catch(Exception e){
  
          }
  
          Dialog.dismiss();
  
      }
  
      public String readJSONFeed(String URL) {
          StringBuilder stringBuilder = new StringBuilder();
          HttpClient httpClient = new DefaultHttpClient();
          HttpGet httpGet = new HttpGet(URL);
          try {
              HttpResponse response = httpClient.execute(httpGet);
              StatusLine statusLine = response.getStatusLine();
              int statusCode = statusLine.getStatusCode();
              if (statusCode == 200) {
                  HttpEntity entity = response.getEntity();
                  InputStream inputStream = entity.getContent();
                  BufferedReader reader = new BufferedReader(
                          new InputStreamReader(inputStream));
                  String line;
                  while ((line = reader.readLine()) != null) {
                      stringBuilder.append(line);
                  }
                  inputStream.close();
              } else {
                  Log.d("JSON", "Failed to download file");
              }
          } catch (Exception e) {
              Log.d("readJSONFeed", e.getLocalizedMessage());
          }
          return stringBuilder.toString();
      }
  
  }
  </code></pre>
  
  <p>My problem is that I can not pass 'this' from a fragment...</p>
  
  <p>Bonus Question:</p>
  
  <p>Also as you can see I am not done converting my code for the fragments. I need to change this to load a fragment instead of change activity:</p>
  
  <pre><code>//todo: change fragment to beer page
                          Intent myIntent = new Intent(c, BeerPage2.class);
                          myIntent.putExtra("id", tempID);
                          myIntent.putExtra("breweryID", tempBrewID);
                          c.startActivity(myIntent);
  </code></pre>
  
  <p>HOw can I pass values between fragments like I am doing between activities in that above code?</p>