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.example.yqltutorial; //from www. j a v a2s . c o 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 tweets; String pimage; 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 tweets tweets = i.getStringExtra("tweets"); // Get the result of pimage pimage = i.getStringExtra("pimage"); // Download the Image from the result URL given by pimage URL url = new URL(pimage); 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 txttweets = (TextView) findViewById(R.id.tweets); // Locate the ImageView in singleitemview.xml ImageView pimg = (ImageView) findViewById(R.id.pimage); // Set results to the TextView txttweets.setText(tweets); // Set results to the ImageView pimg.setImageBitmap(bmImg); // Close the progressdialog mProgressDialog.dismiss(); } } }