1 1. public class Images extends Activity
2 2. {
3 3. private Uri[] mUrls;
4 4. String[] mFiles=null;
5 5.
6 6. public void onCreate(Bundle icicle)
7 7. {
8 8.
9 9. super.onCreate(icicle);
10 10. setContentView(R.layout.images);
11 11.
12 12. File images = Environment.getDataDirectory();
13 13. File[] imagelist = images.listFiles(new FilenameFilter(){
14 14. @override
15 15. public boolean accept(File dir, String name)
16 16. {
17 17. return ((name.endsWith(".jpg"))||(name.endsWith(".png"))
18 18. }
19 19. });
20 20. mFiles = new String[imagelist.length];
21 21.
22 22. for(int i= 0 ; i< imagelist.length; i++)
23 23. {
24 24. mFiles[i] = imagelist[i].getAbsolutePath();
25 25. }
26 26. mUrls = new Uri[mFiles.length];
27 27.
28 28. for(int i=0; i < mFiles.length; i++)
29 29. {
30 30. mUrls[i] = Uri.parse(mFiles[i]);
31 31. }
32 32.
33 33. Gallery g = (Gallery) findViewById(R.id.gallery);
34 34. g.setAdapter(new ImageAdapter(this));
35 35. g.setFadingEdgeLength(40);
36 36. }
37 37. public class ImageAdapter extends BaseAdapter{
38 38.
39 39. int mGalleryItemBackground;
40 40. public ImageAdapter(Context c) {
41 41. mContext = c;
42 42. }
43 43. public int getCount(){
44 44. return mUrls.length;
45 45. }
46 46. public Object getItem(int position){
47 47. return position;
48 48. }
49 49. public long getItemId(int position) {
50 50. return position;
51 51. }
52 52. public View getView(int position, View convertView, ViewGroup parent){
53 53. ImageView i = new ImageView(mContext);
54 54.
55 55. i.setImageURI(mUrls[position]);
56 56. i.setScaleType(ImageView.ScaleType.FIT_XY);
57 57. i.setLayoutParams(new Gallery.LayoutParams(260, 210));
58 58. return i;
59 59. }
60 60. private Context mContext;
61 61. }
62 62. }