1

In my app i got a galleryview. All the pictures are thumpsnails, and i want to open the picture in some kind of action view when it's selected.

But i can't seem to find out quite how. Can any one help?

EDIT: My gallery is not loaded from the SD card. It's generated with pictures from the resource dir inside the app.

My code:

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 in advance.

Kano
  • 1,433
  • 2
  • 12
  • 18
  • previously answered question.. http://stackoverflow.com/questions/3376572/get-selected-image-file-location-in-android – wurde Jan 03 '12 at 00:25
  • My gallery is not loaded from the SD card. It's generated with pictures from the resource dir. So I can't use that method either. Maybe i should post some more code, to make it easier to understand. – Kano Jan 03 '12 at 00:29

1 Answers1

0

Here is a Tutorial that shows you exactly how to do what you are looking for.

Gallery To Imageview Example

coder_For_Life22
  • 26,645
  • 20
  • 86
  • 118
  • Thanks for the answer. But i was aware of that method. What I'm looking for is a way to open the picture in fullscreen out of the app. In some kind of action view? Kind of like when you open a homepage with an intent. – Kano Jan 02 '12 at 23:58