0

我可以使用 xml 解析将选定的列表视图文本发送到另一个活动,但无法将选定的图像提取到下一个活动,我在这里放置我的代码,请找出我没有将图像发送到另一个活动的原因:-

主要活动代码:-

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);
                    }

                });

第二活动代码:-

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);
4

3 回答 3

0

我认为你KEY_THUMB_URL是你的 url 只需在你的第二个 Activity 中调用这个方法这是返回一个位图然后这个位图设置你的图像视图

 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;
}
于 2012-10-13T08:18:27.157 回答
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;
    }
}
于 2012-10-13T08:14:39.073 回答
0

我找到了为什么我没有在下一个活动中获取图像的原因。我犯了一个非常小的错误,请参见下面的行,这是我之前使用的:

 final String thumb_url = in.getStringExtra(KEY_THUMBURL); 

现在我尝试了:

final String imageUri = in.getStringExtra(KEY_THUMBURL); 

因为我正在使用这个变量:

static final String KEY_THUMBURL = "imageUri";
于 2012-10-13T10:28:54.227 回答