如何在android中的自定义列表视图中显示所选项目图像的另一页面

时间:2012-04-28 11:15:01

标签: android web-services android-listview

我从自定义lisview中获取服务器数据库中的itemname,itemimage,price和desc到android mobile。我在自定义列表视图中放置了复选框。我在自定义列表视图中选择了一些项目。现在我想将那些选定的itemimages显示到另一页..请给出解决方案

             i try this code

            public class test extends BaseAdapter {
public Context Context;
  String qrimage;
  Bitmap bmp, resizedbitmap;
  Bitmap[] bmps;
  Activity activity = null;
  private LayoutInflater inflater;

  private ImageView[] mImages;
  String[] itemimage;
  TextView[] tv;  
  String itemname,price,desc;
  String[] itemnames;
  String[] prices;
  String[] descs;
  HashMap<String, String> map = new HashMap<String, String>();

  public Appetizerlist(Context context, JSONArray imageArrayJson) {
      Context=context;
    //inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    //  imageLoader=new ImageLoader(activity);
    inflater=LayoutInflater.from(context);
    this.mImages = new ImageView[imageArrayJson.length()];
    this.bmps = new Bitmap[imageArrayJson.length()];
    this.itemnames = new String[imageArrayJson.length()];
    this.prices=new String[imageArrayJson.length()];
    this.descs=new String[imageArrayJson.length()];
    try {

      for (int i = 0; i < imageArrayJson.length(); i++) {
        JSONObject image = imageArrayJson.getJSONObject(i);
        qrimage = image.getString("itemimage");
        itemname = image.getString("itemname");
        price=image.getString("price");
        desc=image.getString("itemdesc");

        itemnames[i] = itemname;
        prices[i]=price;
       descs[i]=desc;


        byte[] qrimageBytes = Base64.decode(qrimage.getBytes());

        bmp = BitmapFactory.decodeByteArray(qrimageBytes, 0,
                                            qrimageBytes.length);
        int width = 100;
        int height = 100;
        resizedbitmap = Bitmap.createScaledBitmap(bmp, width, height,
                                                  true);
        bmps[i] = bmp;

        mImages[i] = new ImageView(context);
        mImages[i].setImageBitmap(resizedbitmap);

        mImages[i].setScaleType(ImageView.ScaleType.FIT_START);


        // tv[i].setText(itemname);
      }
      System.out.println(map);

    } catch (Exception e) {
      // TODO: handle exception
    }
  }

  public int getCount() {
    return mImages.length;
  }

  public Object getItem(int position) {
    return position;
  }

  public long getItemId(int position) {
    return position;
  }




  public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        final ViewHolder viewHolder;
        if (view == null) {         
              view = inflater.inflate(R.layout.appetiserlistview, null);
            viewHolder = new ViewHolder();
            viewHolder.image=(ImageView)view.findViewById(R.id.appetiserimage);
            viewHolder.text = (TextView) view.findViewById(R.id.appetisertext);
            viewHolder.desc=(TextView)view.findViewById(R.id.appetiserdesc);
            viewHolder.price=(TextView)view.findViewById(R.id.appetiserdesc);
            viewHolder.checkbox = (CheckBox) view.findViewById(R.id.bcheck);


            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.image.setImageBitmap(bmps[position]);

        viewHolder.price.setText(prices[position]);
        viewHolder.desc.setText(descs[position]);
        viewHolder.checkbox.setTag(itemnames[position]);
        ViewHolder holder = (ViewHolder) view.getTag();
        holder.text.setText(itemnames[position]);

        return view;
    }

    static class ViewHolder {
    protected TextView text,price,desc;
    protected ImageView image;
    protected CheckBox checkbox;
}



} 

我希望将所选的项目图像显示到下一页..请帮帮我

1 个答案:

答案 0 :(得分:0)

您可以使用OnItemClickListener()使用qrimage = image.getString("itemimage");将此图像字符串intent.putExtra("qrimage",qrimage);传递到新活动,并在新活动中解码此字符串,就像在ListView中一样。

如果有一个图像数组使用ArrayList来存储每个图像并使用intent.putStringArrayListExtra("arrImages", bmps);将arrayList传递给intent,并使用

将其传入另一个Activity中
Intent i = getIntent();  
arrImages = i.getStringArrayListExtra("arrImages");

希望它有所帮助。