Back to project page Android-Parsing-YQL-using-JSON-Tutorial.
The source code is released under:
Apache License
If you think the Android project Android-Parsing-YQL-using-JSON-Tutorial listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.androidbegin.yqltutorial; /* ww w . ja v a 2 s. co m*/ import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; import android.app.Activity; import android.app.ProgressDialog; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.AsyncTask; import android.os.Bundle; import android.util.Log; import android.widget.ImageView; import android.widget.TextView; public class SingleItemView extends Activity { // Declare Variables String title; String description; String thumbnail; ProgressDialog mProgressDialog; Bitmap bmImg = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Get the view from singleitemview.xml setContentView(R.layout.singleitemview); // Execute loadSingleView AsyncTask new loadSingleView().execute(); } public class loadSingleView extends AsyncTask<String, String, String> { @Override protected void onPreExecute() { super.onPreExecute(); // Create a progressdialog mProgressDialog = new ProgressDialog(SingleItemView.this); // Set progressdialog title mProgressDialog.setTitle("Android Parsing YQL in JSON Tutorial"); // Set progressdialog message mProgressDialog.setMessage("Loading..."); mProgressDialog.setIndeterminate(false); // Show progressdialog mProgressDialog.show(); } @Override protected String doInBackground(String... args) { try { // Retrieve data from ListViewAdapter on click event Intent i = getIntent(); // Get the result of title title = i.getStringExtra("title"); // Get the result of description description = i.getStringExtra("description"); // Get the result of thumbnail thumbnail = i.getStringExtra("thumbnail"); // Download the Image from the result URL given by thumbnail URL url = new URL(thumbnail); HttpURLConnection conn = (HttpURLConnection) url .openConnection(); conn.setDoInput(true); conn.connect(); InputStream is = conn.getInputStream(); bmImg = BitmapFactory.decodeStream(is); } catch (IOException e) { Log.e("Error", e.getMessage()); e.printStackTrace(); } return null; } @Override protected void onPostExecute(String args) { // Locate the TextView in singleitemview.xml TextView txttitle = (TextView) findViewById(R.id.title); TextView txtdescription = (TextView) findViewById(R.id.description); // Locate the ImageView in singleitemview.xml ImageView thumbnail = (ImageView) findViewById(R.id.thumbnail); // Set results to the TextView txttitle.setText(title); txtdescription.setText(description); // Set results to the ImageView thumbnail.setImageBitmap(bmImg); // Close the progressdialog mProgressDialog.dismiss(); } } }