我可以使用xml解析将选定的列表视图文本发送到另一个活动,但是无法将所选图像提取到下一个活动,这里我放置了我的代码,请找出我没有将图像转换为其他活动的原因: -
MainActivity Code: -
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
HashMap<String, String> map = pizzaList.get(position);
Intent in = new Intent(MainActivity.this, SecondActivity.class);
in.putExtra(KEY_TITLE, map.get(KEY_TITLE));
in.putExtra(KEY_DESCRIPTION, map.get(KEY_DESCRIPTION));
in.putExtra(KEY_THUMB_URL, map.get(KEY_THUMB_URL));
in.putExtra(KEY_COST, map.get(KEY_COST));
startActivity(in);
}
});
SecondActivity Code: -
Intent in = getIntent();
final String title = in.getStringExtra(KEY_TITLE);
final String description = in.getStringExtra(KEY_DESCRIPTION);
final String thumb_url = in.getStringExtra(KEY_THUMBURL);
final String cost = in.getStringExtra(KEY_COST);
TextView title = (TextView) findViewById(R.id.single_title);
TextView description = (TextView) findViewById(R.id.single_description);
TextView cost = (TextView) findViewById(R.id.single_cost);
ImageLoader imageLoader = new ImageLoader(getApplicationContext());
ImageView thumb = (ImageView) findViewById(R.id.single_image);
title.setText(title);
description.setText(description);
cost.setText(cost);
imageLoader.DisplayImage(thumb_url, thumb);
答案 0 :(得分:0)
final String title = in.getStringExtra(KEY_TITLE);
final String description = in.getStringExtra(KEY_DESCRIPTION);
final String thumb_url = in.getStringExtra(KEY_THUMBURL);
log.i("log_tag","Image URl:"+thumb_url);
final String cost = in.getStringExtra(KEY_COST);
TextView title = (TextView) findViewById(R.id.single_title);
TextView description = (TextView) findViewById(R.id.single_description);
TextView cost = (TextView) findViewById(R.id.single_cost);
ImageView thumb = (ImageView) findViewById(R.id.single_image);
title.setText(title);
description.setText(description);
cost.setText(cost);
Drawable d = LoadImageFromWebOperations(ImageUrl);
imageView.setImageDrawable(d);
public static Drawable LoadImageFromWebOperations(String url) {
try {
InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
return d;
} catch (Exception e) {
return null;
}
}
答案 1 :(得分:0)
我认为您的KEY_THUMB_URL
是您的网址,只需在您的第二个活动中调用此方法,这将返回一个位图,然后此位图将您设置为图像视图
public static Bitmap loadBitmap(String imgPath) {
String imgUrlStr = imgPath ;
Bitmap bitmap = null;
try {
bitmap = BitmapFactory.decodeStream((InputStream)new URL(imgUrlStr).getContent());
}
catch (MalformedURLException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
return bitmap;
}
答案 2 :(得分:0)
我找到了为什么我没有将图像带入下一个活动的原因。 我做了一个非常小的错误,见下面的行,我之前使用过:
final String thumb_url = in.getStringExtra(KEY_THUMBURL);
现在我尝试过:
final String imageUri = in.getStringExtra(KEY_THUMBURL);
因为我正在使用这个变量:
static final String KEY_THUMBURL = "imageUri";