im using sax parser,asynctask.eclipse juno.
here is where im stucked at:
i already parsed some tags and are appearing on my ListView, when the user tap/click a row of the lisview it should open a new intent,it is open the new layout but is blank, well, the title,author,guid tags are appearing on the list view and i want them to appear too when the new layout/class is open, and also i want to display the description :
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
Intent intent=new Intent(SAXParserAsyncTaskActivity.this,MessageActivity.class);
startActivity(intent);
}
i know i need to put some code on the code above to display the tags that i already have on the Listview,.thats the thing i don't know how to do that !
here is the code, this is code as is,its open with the button the list of messages and when i click on message it just opens a new layout in blank,i want to pass the info from the list view to this layout.
this is the SAXParserAsynctaskActivity(main activity):
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;
import com.theopentutorials.android.adapters.CustomListViewAdapter;
import com.theopentutorials.android.beans.Laptop;
import com.theopentutorials.android.xml.sax.SAXXMLParser;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListView;
public class SAXParserAsyncTaskActivity extends Activity implements
OnClickListener, OnItemClickListener {
Button button;
ListView listView;
List<Laptop> laptops;
CustomListViewAdapter listViewAdapter;
static final String URL = "http://www.revgrades.com/laptops.xml";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findViewsById();
button.setOnClickListener(this);
listView.setOnItemClickListener(this);
}
private void findViewsById() {
button = (Button) findViewById(R.id.button);
listView = (ListView) findViewById(R.id.laptopList);
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
Intent intent=new Intent(SAXParserAsyncTaskActivity.this,MessageActivity.class);
startActivity(intent);
}
@Override
public void onClick(View view) {
GetXMLTask task = new GetXMLTask(this);
task.execute(new String[] { URL });
}
//private inner class extending AsyncTask
private class GetXMLTask extends AsyncTask<String, Void, List<Laptop>> {
private Activity context;
public GetXMLTask(Activity context) {
this.context = context;
}
@Override
protected void onPostExecute(List<Laptop> laptops) {
listViewAdapter = new CustomListViewAdapter(context, laptops);
listView.setAdapter(listViewAdapter);
}
/* uses HttpURLConnection to make Http request from Android to download
the XML file */
private String getXmlFromUrl(String urlString) {
StringBuffer output = new StringBuffer("");
try {
InputStream stream = null;
URL url = new URL(urlString);
URLConnection connection = url.openConnection();
HttpURLConnection httpConnection = (HttpURLConnection) connection;
httpConnection.setRequestMethod("GET");
httpConnection.connect();
if (httpConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
stream = httpConnection.getInputStream();
BufferedReader buffer = new BufferedReader(
new InputStreamReader(stream));
String s = "";
while ((s = buffer.readLine()) != null)
output.append(s);
}
} catch (Exception ex) {
ex.printStackTrace();
}
return output.toString();
}
@Override
protected List<Laptop> doInBackground(String... urls) {
List<Laptop> laptops = null;
String xml = null;
for (String url : urls) {
xml = getXmlFromUrl(url);
InputStream stream = new ByteArrayInputStream(xml.getBytes());
laptops = SAXXMLParser.parse(stream);
for (Laptop laptop : laptops) {
String imageURL = laptop.getImageURL();
Bitmap bitmap = null;
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
bmOptions.inSampleSize = 1;
try {
bitmap = BitmapFactory
.decodeStream(new
URL(imageURL).openStream(),
null, bmOptions);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
laptop.setImageBitmap(bitmap);
}
}
// stream.close();
return laptops;
}
}
}