0

Hi I am pretty new to android and I am basically stuck. I have some paths of images (e.g. String Path) and I want to display these images on a GridView.

This is the class which practically inflates a layout composed of a GridView.

public class FragmentLayout extends Fragment
{
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        //String path = "/mnt/sdcard/Android/data/com.android.browser/files/Download/2014-01-10-00-13-39--1894493676.jpeg";

        View rootView = inflater.inflate(R.layout.fragment_layout, container, false);
        return rootView;
    }
}

Any guidelines please?

Soma
  • 861
  • 2
  • 17
  • 32
user3189635
  • 1
  • 1
  • 3
  • 1
    Read [THIS](http://developer.android.com/guide/topics/ui/layout/gridview.html), after that [THIS](http://developer.android.com/training/displaying-bitmaps/load-bitmap.html) – Eddy Jan 13 '14 at 13:29
  • so you just want to display images in gridView or something special? – Saqib Jan 13 '14 at 13:34
  • no just display the image in a gridview – user3189635 Jan 13 '14 at 13:37
  • till now I have only one path, but I may have more than one that's why I am using a gridView and not an imageview... – user3189635 Jan 13 '14 at 13:38

3 Answers3

0

Since you are a newbie to android, you might be better off going with a third-party library than writing your own container for images in a gridview. Caching and load times will be an issue most people don't think of. Take a look at this thread:

Lazy load of images in ListView

LazyList (specifically, this post: https://stackoverflow.com/a/8562313/2066079) might be a huge help to you, though it might be overkill.

If you know the paths beforehand, you can make them a drawable, create an ImageView for each, and then throw them in a GridLayout. the reason I choose GridLayout over GridView is for compatibility with older devices.

To make the images fill the Grid container, I found this post: very useful: GridLayout (not GridView) how to stretch all children evenly But like I said - caching and load times will be an issue if the images are large, or if there are more than a handful of them.

Community
  • 1
  • 1
dberm22
  • 3,187
  • 1
  • 31
  • 46
0

SEE these examples for help

http://www.androidhive.info/2012/02/android-gridview-layout-tutorial/

http://androidprogramz.blogspot.in/2012/07/display-images-in-gridview.html

http://www.tutorialspoint.com/android/android_grid_view.htm

You can do this for chaging images or just create array of drawables

if (mobile.equals("Windows")) {
                imageView.setImageResource(R.drawable.windows_logo);
            } else if (mobile.equals("iOS")) {
                imageView.setImageResource(R.drawable.ios_logo);
            } else if (mobile.equals("Blackberry")) {
                imageView.setImageResource(R.drawable.blackberry_logo);
            } else {
                imageView.setImageResource(R.drawable.android_logo);
            }

OR

ArrayList<Integer> myImageList = new ArrayList<Integer>();
myImageList.add(R.drawable.thingOne);
// later...
myImageView.setImageResouce(myImageList.get(i));
keshav
  • 3,235
  • 1
  • 16
  • 22
0

If they are just static images, copy them into your drawable folder then you can pretty use the exact example which is on the android docs about grid view:

http://developer.android.com/guide/topics/ui/layout/gridview.html

Dreagen
  • 1,733
  • 16
  • 21