2012-08-23 62 views
0

我已經使android應用程序從數據庫中提取圖像(MYSQL)使用php.I也獲得圖像,但問題是,我想要傳遞圖像到另一個活動,即從gridview查看flipper以便滑動圖像。得到imageurl點擊圖像的gridview

請任何人可以幫助我如何傳遞從數據庫中獲取的點擊圖像。

在此先感謝。

DisplayActivity.java

公共類DisplayImages延伸活動{

ImageView imageview; 
JSONObject json1= JSONfunction.getJSONfromURL("http://www.zxxxxcssxxxxxx.com/app/photo.php"); 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_display_images); 

     JSONArray catgry = null; 
    try { 
     catgry = json1.getJSONArray("photo"); 
    } catch (JSONException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

    final GridView gridView=(GridView)findViewById(R.id.gridview); 
    ImageAdapter adapter=new ImageAdapter(this,catgry); 
    gridView.setAdapter(adapter); 


    /** 
    * On Click event for Single Gridview Item 
    * */ 

    gridView.setOnItemClickListener(new OnItemClickListener(){ 

    public void onItemClick(AdapterView<?> parent, View view, int position, 
      long id) { 
     // TODO Auto-generated method stub 

     Image img=new Image(); 
     Object imagename=view.getTag(); 

     if(position==0) 
     img.setImageBitmap(getImageBitmap("http://www.aaa.com/thumb_photo_3.jpg")); 
     if(position==1) 
      img.setImageBitmap(getImageBitmap("http://www.aaa.com/thumb_photo_4.jpg")); 
     if(position==2) 
      img.setImageBitmap(getImageBitmap("http:/www.aaa.com/thumb_photo_5.jpg")); 
     if(position==3) 
      img.setImageBitmap(getImageBitmap("http://www.aaa.com/thumb_photo_6.jpg")); 
     if(position==4) 
      img.setImageBitmap(getImageBitmap("http://www.aaa.com/thumb_photo_7.jpg")); 
     if(position==5) 
      img.setImageBitmap(getImageBitmap("http://www.aaa.com/thumb_photo_8.jpg")); 
     if(position==6) 
      img.setImageBitmap(getImageBitmap("http://www.aaa.com/thumb_photo_9.jpg")); 
     if(position==7) 
      img.setImageBitmap(getImageBitmap("http://www.aaa.com/thumb_photo_10.jpg")); 
     if(position==8) 
      img.setImageBitmap(getImageBitmap("http://www.aaa.com/thumb_photo_11.jpg")); 
     if(position==9) 
      img.setImageBitmap(getImageBitmap("http://www.aaa.com/thumb_photo_12.jpg")); 
     if(position==10) 
      img.setImageBitmap(getImageBitmap("http://www.aaa.com/thumb_photo_13.jpg")); 

     Toast.makeText(DisplayImages.this, "" + imagename, 
       Toast.LENGTH_SHORT).show(); 

     Intent intent=new Intent(getApplicationContext(),FullSizeImageActivity.class); 
     //Create Parcelable object 
     ParcelableImage parcelableImage=new ParcelableImage(img); 

     //store Parcelable Object in intent 
     intent.putExtra("img", parcelableImage); 
     startActivity(intent); 
    } 

    }); 
} 

private Bitmap getImageBitmap(String url) { 
    Bitmap bm = null; 
    try { 
     URL aURL = new URL(url); 
     URLConnection conn = aURL.openConnection(); 
     conn.connect(); 
     InputStream is = conn.getInputStream(); 
     BufferedInputStream bis = new BufferedInputStream(is); 
     bm = BitmapFactory.decodeStream(bis); 
     bis.close(); 
     is.close(); 
    } catch (IOException e) { 
     //Log.e(TAG, "Error getting bitmap", e); 
    } 
    return bm; 
} 

}

我傳遞的圖像路徑的onclick那個位置的gridview.but我想要得到的圖像路徑onclick image.how我可以動態獲取圖像路徑並傳遞另一個活動。

這是我的形象適配器的代碼

公共類ImageAdapter延伸BaseAdapter {

public ImageView[] mImages; 
String qrimage; 
static class ViewHolder{ 

    ImageView image; 
} 

JSONObject json1= JSONfunction.getJSONfromURL("http://www.zzzzzxxxxxxxxxx.com/app/photo.php"); 

private Context context; 

public ImageAdapter(Context mcontext,JSONArray imageArrayJson) { 
    // TODO Auto-generated constructor stub 
    this.context=mcontext; 
    this.mImages = new ImageView[imageArrayJson.length()]; 


    for(int i=0;i<imageArrayJson.length();i++){ 

     JSONObject image; 
     try { 
      ImageView imageView; 
      imageView = new ImageView(context); 

      imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); 
      imageView.setLayoutParams(new GridView.LayoutParams(90, 90)); 
      image = imageArrayJson.getJSONObject(i); 
      qrimage="http://www.aaa.com/"+image.getString("thumbsize"); 

      //imageView.setImageBitmap(getImageBitmap(qrimage)); 
      mImages[i]= new ImageView(context); 
      mImages[i].setImageBitmap(getImageBitmap(qrimage)); 
      mImages[i].setTag("Image"+i); 

     } catch (JSONException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
    } 

} 

回答

0

如果你想通過activites之間的事情,你會想要做這樣的事情:

How do I pass an object from one activity to another on Android?

你從數據庫中獲取數據,但沒有什麼會改變。

+0

感謝您的回覆。我想獲得點擊圖片的網址並傳遞到另一個活動 – raju2k11

+0

然後我說的將工作。 – Michael

+0

它正在working.but知道問題出現我怎樣才能得到點擊圖像的網址,以便我可以使用parcelable – raju2k11