2012-01-02 49 views
1

在我的應用程序中,我收到了一個galleryview。所有圖片都是thumpsnails,我想在選擇某種動作視圖時打開圖片。Android - 在Action視圖中打開所選圖片?

但我似乎無法找出如何。任何人都可以幫忙嗎?編輯: 我的畫廊不是從SD卡加載。它是由應用程序內資源目錄中的圖片生成的。

我的代碼:

import dk.appsfabrikken.iphonetabs.R; 
import android.app.Activity; 
import android.content.Context; 
import android.content.Intent; 
import android.content.res.Configuration; 
import android.content.res.TypedArray; 
import android.net.Uri; 
import android.os.Bundle; 
import android.view.View; 
import android.view.ViewGroup; 
import android.view.View.OnClickListener; 
import android.widget.AdapterView; 
import android.widget.BaseAdapter; 
import android.widget.Button; 
import android.widget.Gallery; 
import android.widget.ImageView; 
import android.widget.AdapterView.OnItemClickListener; 

public class CombarActivity extends Activity { 
    private Gallery gallery; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.combar); 

     //Knapper instantieres 
     Button butMarked = (Button)findViewById(R.id.btmarket); 

     //Opretter on click listerner til enkelt klik 
     butMarked.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
      onclick_btmarket(); 

      } 
     }); 

     //Gallery findes på layout 
     gallery = (Gallery) findViewById(R.id.gallery1); 
     gallery.setAdapter(new AddImgAdp(this)); 

     //Onlick listerner oprettes 
     gallery.setOnItemClickListener(new OnItemClickListener() { 
     public void onItemClick(AdapterView<?> parent, View v, int position, long id) { 
     } 
     }); 

     } 

     public class AddImgAdp extends BaseAdapter { 
     int GalItemBg; 
     private Context cont; 

     // Tilføjer billeder til gallery 
     private Integer[] Imgid = { 
     R.drawable.combar2, R.drawable.combar1}; 

     public AddImgAdp(Context c) { 
     cont = c; 
     TypedArray typArray = obtainStyledAttributes(R.styleable.GalleryTheme); 
     GalItemBg = typArray.getResourceId(R.styleable.GalleryTheme_android_galleryItemBackground, 0); 
     typArray.recycle(); 
     } 

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

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

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

     public View getView(int position, View convertView, ViewGroup parent) { 
     ImageView imgView = new ImageView(cont); 

     imgView.setImageResource(Imgid[position]); 
     // Tilpasser højde og bredde for billeder i gallery. Tester skærmstørrelse og tilpasser. 
     if ((getResources().getConfiguration().screenLayout &  Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_SMALL) { 
      imgView.setLayoutParams(new Gallery.LayoutParams(110, 170)); 
     } 
     else{ 
     imgView.setLayoutParams(new Gallery.LayoutParams(220, 340)); 
     } 
     imgView.setScaleType(ImageView.ScaleType.FIT_XY); 
     imgView.setBackgroundResource(GalItemBg); 

     return imgView; 
     } 
     } 
     //Udfører opgave for click på knap 
     private void onclick_btmarket() { 
      Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://market.android.com/details?id=dk4.ef.cms")); 
      startActivity(browserIntent);} 

      ; 

     } 

Thanx提前。

+0

前面回答的問題.. http://stackoverflow.com/questions/3376572/get-selected-image-file-location-in-android – wurde 2012-01-03 00:25:49

+0

我的畫廊不從SD卡中加載。 它是由資源目錄中的圖片生成的。所以我也不能使用這種方法。 也許我應該發佈一些更多的代碼,使其更容易理解。 – Kano 2012-01-03 00:29:29

回答

0

這是一個教程,告訴你如何做你正在尋找的東西。

Gallery To Imageview Example

+0

感謝您的回答。但我意識到這種方法。 我正在尋找的是一種在全屏應用程序中打開圖片的方式。在某種行動觀點? 有點像打開主頁時的意圖。 – Kano 2012-01-02 23:58:08