Hi,

         I am trying to get the sd card images and viewing it in grid view.I
can able to get the picture from sd card in gallery view  ,but i want to
view the images in gridview . I am trying a lot but the images is not
appears on the screen in the grid view.Anyone can help me for fixing this
problem or other wise give me some related links related to this .My code is
pasted below


public class GalleryExample extends Activity {

    private Context mContext;
    private Cursor cursor;
    private int column_index;
    private Gallery g;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


        String [] proj={MediaStore.Images.Thumbnails._ID};
        // Now we create the cursor pointing to the external thumbnail store
        cursor = managedQuery(
MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
                proj,
                null,
                null,
                null);

        column_index =
cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);

// this is a reference to gallrey view  and its working
        g = (Gallery) findViewById(R.id.gallery);
        g.setAdapter(new ImageAdapter(this));

// its a reference to grid view but its not working
     //   GridView grd = (GridView)findViewById(R.id.gridview);
       // grd.setAdapter(new ImageAdapter(this));

        g.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView parent, View v, int
position, long id)
            {

               String [] proj={MediaStore.Images.Media.DATA};
               cursor = managedQuery(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                          proj,
                          null,
                          null,
                          null);

              column_index =
cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);

              cursor.moveToPosition((int) g.getSelectedItemId());

              String filename = cursor.getString(column_index);
              Toast.makeText(GalleryExample.this, filename,
Toast.LENGTH_SHORT).show();
            }
        });
    }

    public class ImageAdapter extends BaseAdapter {
        int mGalleryItemBackground;

        public ImageAdapter(Context c) {
            mContext = c;
            // See res/values/attrs.xml for the  that defines
            // Gallery1.
//            TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);
//            mGalleryItemBackground = a.getResourceId(
//                    R.styleable.Gallery1_android_galleryItemBackground,
0);

//for grid view i use
//            a.recycle();
        }

        public int getCount() {
          return cursor.getCount();
        }

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

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

        public View getView(int position, View convertView, ViewGroup
parent) {
          ImageView i = new ImageView(mContext);
          if (convertView == null) {
               cursor.moveToPosition(position);
                    int id = cursor.getInt(column_index);

i.setImageURI(Uri.withAppendedPath(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
""+id));
                    i.setScaleType(ImageView.ScaleType.FIT_XY);
                    i.setLayoutParams(new Gallery.LayoutParams(136, 88));

// for grid view i used  i.setLayoutParams(new Gridview.LayoutParams(136,
88));
                    // The preferred Gallery item background
                    //  i.setBackgroundResource(mGalleryItemBackground);
          }
               return i;
        }
      }
}



-- 
Thanks&Regards,
    JOBI N.K
     Mob   : +91 99 46 40 84 43
              : +91 97 39 45 15 48

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to