没有从项目点击监听器的gridview获取所有图像

时间:2011-04-06 09:42:02

标签: java android android-layout android-widget android-manifest

我正在开发一个应用程序,其中gridview显示来自inter net的图像...现在我想将所有图像传递给gridview的click事件中的图库..

我希望我的画廊不应该在调用图库活动时下载所有图像。所以,我想将所有图像从网格视图传递到图库活动......

是否有任何解决方案可以传递gridview的所有图像o下一个活动,。?

我的gridview的图像来自互联网,我没有在本地存储所有图像......只是在网格视图中显示。

这是我的代码..

mainfile.java

   public class PhotoList extends Activity
{
     Bundle bundle;
     String key;
     int totalPhoto;
     ImageView imageArray[];
     HashMap<String,ArrayList<ChildPhotos>> childPhotosWithId;
     ArrayList<ChildPhotos> childPhotoList;
     String allURL[];
     String title,discription;
     TextView PhotosTitle,PhotosDiscription;
     public static Bitmap[] downloadedChildPhotos;
     public static int downloadedChildPhotosIndex=0;
     ImageView img[];
     public void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.photo_list);


            GridView gridview = (GridView) findViewById(R.id.gridview);
            bundle=getIntent().getExtras();
            key=bundle.getString("key");
            totalPhoto=Integer.parseInt(key);
            img=new ImageView[totalPhoto];
            title=bundle.getString("title");
            discription=bundle.getString("discription");

            childPhotosWithId=PhotosXMLHanler.getChildPhotoWithId();
            childPhotoList=childPhotosWithId.get(key);
            ChildPhotos c[]=new ChildPhotos[childPhotoList.size()];
            allURL=new String[childPhotoList.size()];

            downloadedChildPhotos=new Bitmap[childPhotoList.size()];

            PhotosTitle=(TextView)findViewById(R.id.photosTitleInGridView);
            PhotosDiscription=(TextView)findViewById(R.id.photoDiscriptionInGridView);

            PhotosTitle.setText(title);
            PhotosDiscription.setText(discription);

                for(int i=0;i<childPhotoList.size();i++)
                {
                    c[i]=new ChildPhotos();
                    c[i]=childPhotoList.get(i);
                    String url=c[i].getChildPhoto();
                    allURL[i]=url;
                    System.out.println("url "+(i+1)+c[i].getChildPhoto());
                }

                gridview.setAdapter(new ImageAdapter(this,allURL));

            gridview.setOnItemClickListener(new OnItemClickListener()
            {
                public void onItemClick(AdapterView<?> parent, View v, int position, long id)
                {
                Toast.makeText(PhotoList.this, "" +id, Toast.LENGTH_SHORT).show();
                GridView g=(GridView)v.findViewById(R.id.gridview);

                    for(int i=0;i<totalPhoto;i++)
                    {
                    img[i]=new ImageView(PhotoList.this);

                    System.out.println("image ==>"+img[i].getId());
                    }

                /*

                here i want to fetch all images from grid view...


                */


//              Intent intent=new Intent(PhotoList.this,GalleryView.class);
//              
//              startActivityForResult(intent, 0);

                }
            });




        }

     class ImageAdapter extends BaseAdapter 
     {
            private Context mContext;
            String[] allURL;
            ImageLoader imageLoader;

            public ImageAdapter(Context c,String[] allURL)
            {
                mContext = c;
                this.allURL=allURL;
                imageLoader =   new ImageLoader(mContext);
            }

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

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


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

            // create a new ImageView for each item referenced by the Adapter
            public View getView(int position, View convertView, ViewGroup parent) {
                ImageView imageView;
                if (convertView == null)
                { 
                    // if it's not recycled, initialize some attributes
                    imageView = new ImageView(mContext);
                    imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
                    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                    imageView.setPadding(8, 8, 8, 8);
                } 
                else 
                {
                    imageView = (ImageView) convertView;
                }
                 imageView.setTag(allURL[position]);

                 imageLoader.DisplayImage(allURL[position],PhotoList.this,imageView);
                 ///here i use thread which set image in backgrund...as images come from internet..



                 return imageView;
            }

        }

}

1 个答案:

答案 0 :(得分:2)

当您在gridview中单击一个图像时,您可以将该图像存储在位图中。在注释部分中写下以下代码。

ImageView im=(ImageView) view;  
Drawable d = im.getDrawable();  
Bitmap bitmap = ((BitmapDrawable)d).getBitmap();

同样,您可以存储所有位图,就像单击图像一样。希望这就是您要找的内容。