I use Listviewto display image and data using json parser,
But when I click on one of the elements of the list, the image is not displayed in the next action, that is, in the detailed action.
I use the following code to display an image. Can someone lead me on the right path? Any help would be appreciated.
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
String title = ((TextView) view.findViewById(R.id.title)).getText().toString();
String date = ((TextView) view.findViewById(R.id.date)).getText().toString();
String name = ((TextView) view.findViewById(R.id.name)).getText().toString();
String content = ((TextView) view.findViewById(R.id.content)).getText().toString();
JSONObject json = jParser.getJSONFromUrl(URL);
try {
posts = json.getJSONArray(KEY_POSTS);
for(int i = 0; i < posts.length(); i++){
JSONObject c = posts.getJSONObject(i);
String url = null;
String slug = null;
try {
JSONArray atta = c.getJSONArray("attachments");
for(int j = 0; j < atta.length(); j++){
JSONObject d = atta.getJSONObject(j);
slug = d.getString(KEY_SLUG);
JSONObject images = d.getJSONObject(KEY_IMAGES);
JSONObject thumbnail = images.getJSONObject(KEY_THUMB_URL);
url = thumbnail.getString(KEY_URL);
}
} catch (Exception e) {
e.printStackTrace();
}
Intent in = new Intent(getApplicationContext(),SampleDesp.class);
in.putExtra(KEY_TITLE, title);
in.putExtra(KEY_DATE, date);
in.putExtra(KEY_NAME, name);
in.putExtra(KEY_CONTENT, content);
in.putExtra(KEY_URL, url);
startActivity(in);
}
}catch (JSONException e) {
e.printStackTrace();
}
}
});
}
}
And in Singlemenuitem.java
Intent in = getIntent();
final String url1 = in.getStringExtra(KEY_URL);
ImageView imgv = (ImageView) findViewById(R.id.imgdesc);
ImageLoader imageLoader = new ImageLoader(getApplicationContext());
imageLoader.DisplayImage(url1, imgv);
final String title = in.getStringExtra(TAG_TITLE);
String date = in.getStringExtra(TAG_DATE);
String name = in.getStringExtra(TAG_NAME);
final String content = in.getStringExtra(TAG_CONTENT);
TextView lblName = (TextView) findViewById(R.id.name_label);
TextView lblCost = (TextView) findViewById(R.id.email_label);
TextView lblDesc = (TextView) findViewById(R.id.mobile_label);
TextView lblCont = (TextView) findViewById(R.id.content_label);
lblName.setText(title);
lblCost.setText(date);
lblDesc.setText(name);
lblCont.setText(content);
source
share