Creating a Gallery image in android

public class PicSelectActivity extends Activity {
   
    private final int PICKER = 1;
    private int currentPic = 0;
    //private PicAdapter imgAdapt;
    private Gallery picGallery;
    private ImageView picView;
     Bitmap[] bitmaps;
   
    @Override
    public void onCreate(Bundle savedInstanceState) {
       
         Log.v("******************","process1");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.imagedat);
       
     
       
        NotesDbAdapter objndb = new NotesDbAdapter(this);
        objndb.open();
       
        
         Cursor productCursor = null;
         productCursor = objndb.mDb.query(NotesDbAdapter.PRODUCT_TABLE,new String[] { "product_img", "product_id" }, null, null, null,null, null, null);
         int i=0;
       
       
         Gallery galleryView=(Gallery)findViewById(R.id.gallery);
         bitmaps = new Bitmap[productCursor.getCount];    
         productCursor.moveToFirst();
         while (productCursor.moveToNext())
         {
       
             byte[] imgBytearray = productCursor.getBlob(productCursor.getColumnIndex("product_img"));
             Bitmap bitmap = BitmapFactory.decodeByteArray(imgBytearray, 0,imgBytearray.length);
             bitmaps[i] = bitmap;
             i++;
         }
        
         productCursor.close();
        
         galleryView.setAdapter(new PicAdapter(this, bitmaps));
             
               
       
        galleryView.setOnItemClickListener(new OnItemClickListener() {
           
           
            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                Log.v("******************","process1");
               // picView.setImageBitmap( bitmaps[position]);
            }
        });
    }
   
    public class PicAdapter extends BaseAdapter {
       
       
        private  Bitmap bitmaps[];

        private Context mContext;
    

        //constructor
        public PicAdapter(Context c, Bitmap[] bitmaps) {
            mContext=c;
            bitmaps=bitmaps;
        }

        public int getCount() {
            return bitmaps.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 imageView = new ImageView(mContext);
          
            imageView.setImageBitmap(bitmaps[position]);
           
            imageView.setLayoutParams(new Gallery.LayoutParams(300, 200));
          
            imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
           
            //imageView.setBackgroundResource(defaultItemBackground);
          
            return imageView;
        }
       
    }
}

Comments

Popular posts from this blog

Creating a HorizontalScrollView of Images like Galery from Drawable

Creating New Android Project in Eclipse