0

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

     } 

} 

回答

2

,當你在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