不是项目点击收听正从gridview的所有图像

问题描述:

IM发展,其中从Inter网GridView中显示图片...现在我想所有的图像传递到画廊在GridView的单击事件我想要一个应用程序..不是项目点击收听正从gridview的所有图像

我的画廊不应该下载所有图像时,画廊活动called..so,我想从网格视图图库活动传递所有的图片

有任何解决方案通过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; 
      } 

     } 

} 

,当你在GridView中点击一个图像上可以说图像存储在一个位图。在你的评论部分写下面的代码。

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

同样,你可以存储所有的位图,当图像被点击时。希望这是你在找什么。

+0

烨好友...但是这会给我每次点击只有一个视图。我想从对网格视图中的任何项目单击事件gridview的所有项目......有以任何方式使用“适配器视图>父”参数项目点击事件???我如何获得所有项目? – 2011-04-07 04:20:05

+0

对(INT I = 0; I androidGuy 2011-04-08 12:48:02