Android - AsyncTask Is A Beauty - Part 2
Here goes the second part of a short tutorial of how beautiful AsyncTask is, the first tutorial is here. Now that we’re moving up to our second activity which is Hacktivate, a brief description about it is that this activity essentially puts all the data retrieved previously and populate a custom layout ListView. To make reading and understanding easier, here are the codes first before anything else. package com.bango.acerid; import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.jsoup.Jsoup; import android.app.Activity; import android.content.Intent; import android.graphics.Bitmap; import android.os.AsyncTask; import android.os.Bundle; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; import android.widget.AdapterView.OnItemClickListener; public class Hacktivate extends Activity { private String jsonStr = ""; private JSONObject json; private List images = new ArrayList(); private List titles = new ArrayList(); private List writers = new ArrayList(); private List dates = new ArrayList(); private List links = new ArrayList(); private List body = new ArrayList(); private List description = new ArrayList(); private ArticleAdapter adapter = new ArticleAdapter(); private List l = new ArrayList(); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.hacktivate); Bundle the = getIntent().getExtras(); jsonStr = (the != null) ? the.getString("listData") : ""; parseJson(jsonStr); ListView articleList = (ListView) findViewById(R.id.list); articleList.setAdapter(adapter); final Intent i = new Intent(this, PostViewer.class); articleList.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View v, int position, long id) { i.putExtra("wvUrl", links.get(position)); i.putExtra("wvBody", body.get(position)); Hacktivate.this.startActivity(i); } }); } private void parseJson(String j) { try { json = new JSONObject(j); JSONArray rss = json.getJSONArray("rss"); int max = rss.length(); for(int i=0; i...