java - 未从项目单击监听器上的 gridview 获取所有图像

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

我正在开发一个应用程序,其中 gridview 显示来自互联网的图像...现在我想通过 gridview 的点击事件将所有图像传递到图库..

我希望我的画廊在调用画廊 Activity 时不应下载所有图像。因此,我想将所有图像从 GridView 传递到画廊 Activity ...

是否有任何解决方案可以将 gridview 的所有图像传递给下一个 Activity ?

我的 gridview 的图像来自互联网,我没有将所有图像存储在本地......只是显示在 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;
            }

        }

}

最佳答案

当您单击 gridview 中的一张图像时,您可以将该图像存储在位图中。在您的评论部分写下以下代码。

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

同样,您可以在单击图像时存储所有位图。希望这就是您正在寻找的。

关于java - 未从项目单击监听器上的 gridview 获取所有图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5564348/

相关文章:

java - 在 Spring 数据实体中填充 "created"列

android - 设置 headless 设备以连接到 wifi 网络

android - 突出显示可扩展列表中的选定项目

android - 带谷歌地图的 DrawerLayout

Android获取WebView高度

java - 如何使用 JSONB PostgreSQL 通过 JSON 插入列?

java - 使用 Java 和 MS Access 进行自定义数据库表设计

java - 获取带有线程上下文的堆栈跟踪

java - Android:onClickListener方法未到达结束,因为它先结束

Android 主题、全屏和操作栏