Unable to retreive images from a folder in Android

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

30 Replies - 2867 Views - Last Post: 15 January 2014 - 09:28 PM

#1 San T  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 04-January 14

Unable to retreive images from a folder in Android

Posted 04 January 2014 - 03:07 AM

I am dealing with the PinterestListView from GitHub. I want to load images from a specific folder in SDCard which I am unable to do. The part where I cannot do is where I have Integer array which intakes only integers and not path to images. I tried to implement it with a String array but it messes with the ItemsAdapter(default) class file and throws unwanted error.

CODE :

Integer[] leftItems = new Integer[]{R.drawable.ic_1, R.drawable.frog, R.drawable.lime, R.drawable.dog_0, R.drawable.ic_5};
Integer[] rightItems = new Integer[]{R.drawable.ic_6, R.drawable.ic_7, R.drawable.ic_8, R.drawable.edited, R.drawable.ic_10};
leftAdapter = new ItemsAdapter(this, R.layout.item, leftItems);
rightAdapter = new ItemsAdapter(this, R.layout.item, rightItems);



ImageAdapter.java :

public ItemsAdapter(Context context, int layoutResourceId, Integer[] items) {
  super(context, layoutResourceId, items);
  this.context = context;
  this.layoutResourceId = layoutResourceId;
  float width = ((Activity)context).getWindowManager().getDefaultDisplay().getWidth();
  float margin = (int)convertDpToPixel(10f, (Activity)context);
  imageWidth = ((width - (3 * margin)) / 2);
    }



Question :

How do I add the path of the image file to Integer array so as to load the images from my SDCard ?

I have tried to convert to the string path to integer like

String path = android.os.Environment.getExternalStorageDirectory() + File.separator + "Pictures" + File.separator + "SanPics2";
File file = new File(path,"Image 4.jpg");
String image_path = file.toString();
int pa = Integer.parseInt(image_path);



It didn't work thereby throwing NumberFormatException which did not accept this as Integer.I am not even sure whether this makes sense but I had to try something.

I am also posting the entire ImageAdapter class for reference.

ImageAdapter.java :

public class ItemsAdapter extends ArrayAdapter<Integer>{

    Context context; 
    LayoutInflater inflater;
    int layoutResourceId;
    float imageWidth;

    public ItemsAdapter(Context context, int layoutResourceId, Integer[] items) {
        super(context, layoutResourceId, items);
        this.context = context;
        this.layoutResourceId = layoutResourceId;
        float width = ((Activity)context).getWindowManager().getDefaultDisplay().getWidth();
        float margin = (int)convertDpToPixel(10f, (Activity)context);
        // two images, three margins of 10dips
        imageWidth = ((width - (3 * margin)) / 2);
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        FrameLayout row = (FrameLayout) convertView;
        ItemHolder holder;
        //String item_string = getItem(position);
        int item = getItem(position);

        if (row == null) {
            holder = new ItemHolder();
            inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            row = (FrameLayout) inflater.inflate(layoutResourceId, parent, false);
            ImageView itemImage = (ImageView)row.findViewById(R.id.item_image);
            holder.itemImage = itemImage;
        } else {
            holder = (ItemHolder) row.getTag();
        }

        row.setTag(holder);
        setImageBitmap(item, holder.itemImage);
        return row;
    }

    public static class ItemHolder
    {
        ImageView itemImage;
    }

    // resize the image proportionately so it fits the entire space
    private void setImageBitmap(int item, ImageView imageView){
        Bitmap bitmap = BitmapFactory.decodeResource(getContext().getResources(),item);
        float i = ((float) imageWidth) / ((float) bitmap.getWidth());
        float imageHeight = i * (bitmap.getHeight());
        FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) imageView.getLayoutParams();
        params.height = (int) imageHeight;
        params.width = (int) imageWidth;
        imageView.setLayoutParams(params);
        imageView.setImageResource(item);
    }

    public static float convertDpToPixel(float dp, Context context){
        Resources resources = context.getResources();
        DisplayMetrics metrics = resources.getDisplayMetrics();
        float px = dp * (metrics.densityDpi/160f);
        return px;
    }

}


Any idea on how to bring about the images from SDCard will be highly appreciated. Thanks in advance. This question might be vague, apologies if is it so.

Is This A Good Question/Topic? 0
  • +

Replies To: Unable to retreive images from a folder in Android

#2 EndLessMind  Icon User is offline

  • These are the droids you're looking for
  • member icon

Reputation: 194
  • View blog
  • Posts: 1,099
  • Joined: 13-March 09

Re: Unable to retreive images from a folder in Android

Posted 05 January 2014 - 03:48 PM

To get image from sdcard, you can use

String PATH = Environment.getExternalStorageDirectory() + "/Pictures/SanPics2";

Don't forget, that on some Android versions, you need READ_EXTERNAL_STORAGE permission.
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

This post has been edited by EndLessMind: 05 January 2014 - 03:48 PM

Was This Post Helpful? 0
  • +
  • -

#3 San T  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 04-January 14

Re: Unable to retreive images from a folder in Android

Posted 05 January 2014 - 10:55 PM

View PostEndLessMind, on 05 January 2014 - 03:48 PM, said:

To get image from sdcard, you can use

String PATH = Environment.getExternalStorageDirectory() + "/Pictures/SanPics2";

Don't forget, that on some Android versions, you need READ_EXTERNAL_STORAGE permission.
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />


But I have already tried that the fact is that I am using ArrayAdapter<Integer> which can be changed to string but this requires a lot of conversion in future which I would like to avoid. My question is that, is there any way to convert the string path to in and pass in the Integer array. I have already tried Integer.parseInt() but it doesn't work either. You can take a look at the ItemsAdapter.java which would explain why it wont work.
Was This Post Helpful? 0
  • +
  • -

#4 EndLessMind  Icon User is offline

  • These are the droids you're looking for
  • member icon

Reputation: 194
  • View blog
  • Posts: 1,099
  • Joined: 13-March 09

Re: Unable to retreive images from a folder in Android

Posted 06 January 2014 - 08:07 AM

Okay. But you can't just convert strings to integer.
Integer is numbers and string is characters.
You need to change your adapter and the data that you feed it.

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;



	public class ItemsAdapter extends ArrayAdapter<String>{

	    Context context; 
	    LayoutInflater inflater;
	    int layoutResourceId;
	    float imageWidth;

	    public ItemsAdapter(Context context, int layoutResourceId, String[] items) {
	        super(context, layoutResourceId, items);
	        this.context = context;
	        this.layoutResourceId = layoutResourceId;
	        float width = ((Activity)context).getWindowManager().getDefaultDisplay().getWidth();
	        float margin = (int)convertDpToPixel(10f, (Activity)context);
	        // two images, three margins of 10dips
	        imageWidth = ((width - (3 * margin)) / 2);
	    }


	    @Override
	    public View getView(int position, View convertView, ViewGroup parent) {
	        FrameLayout row = (FrameLayout) convertView;
	        ItemHolder holder;
	        
	        String item = getItem(position);

	        if (row == null) {
	            holder = new ItemHolder();
	            inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	            row = (FrameLayout) inflater.inflate(layoutResourceId, parent, false);
	            
	            /**
	             * You need to change this part, to load image from sd-card
	             */
	            //ImageView itemImage = (ImageView)row.findViewById(R.id.item_image);
	            //holder.itemImage = itemImage;
	        } else {
	            holder = (ItemHolder) row.getTag();
	        }

	        row.setTag(holder);
	       // setImageBitmap(item, holder.itemImage);
	        return row;
	    }

	    public static class ItemHolder
	    {
	        ImageView itemImage;
	    }

	    
	    // resize the image proportionately so it fits the entire space
	    private void setImageBitmap(int item, ImageView imageView){
	        Bitmap bitmap = BitmapFactory.decodeResource(getContext().getResources(),item);
	        float i = ((float) imageWidth) / ((float) bitmap.getWidth());
	        float imageHeight = i * (bitmap.getHeight());
	        FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) imageView.getLayoutParams();
	        params.height = (int) imageHeight;
	        params.width = (int) imageWidth;
	        imageView.setLayoutParams(params);
	        imageView.setImageResource(item);
	    }

	    public static float convertDpToPixel(float dp, Context context){
	        Resources resources = context.getResources();
	        DisplayMetrics metrics = resources.getDisplayMetrics();
	        float px = dp * (metrics.densityDpi/160f);
	        return px;
	    }

	}



That's basically it.
Was This Post Helpful? 1
  • +
  • -

#5 San T  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 04-January 14

Re: Unable to retreive images from a folder in Android

Posted 06 January 2014 - 10:41 AM

View PostEndLessMind, on 06 January 2014 - 08:07 AM, said:

Okay. But you can't just convert strings to integer.
Integer is numbers and string is characters.
You need to change your adapter and the data that you feed it.

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;



	public class ItemsAdapter extends ArrayAdapter<String>{

	    Context context; 
	    LayoutInflater inflater;
	    int layoutResourceId;
	    float imageWidth;

	    public ItemsAdapter(Context context, int layoutResourceId, String[] items) {
	        super(context, layoutResourceId, items);
	        this.context = context;
	        this.layoutResourceId = layoutResourceId;
	        float width = ((Activity)context).getWindowManager().getDefaultDisplay().getWidth();
	        float margin = (int)convertDpToPixel(10f, (Activity)context);
	        // two images, three margins of 10dips
	        imageWidth = ((width - (3 * margin)) / 2);
	    }


	    @Override
	    public View getView(int position, View convertView, ViewGroup parent) {
	        FrameLayout row = (FrameLayout) convertView;
	        ItemHolder holder;
	        
	        String item = getItem(position);

	        if (row == null) {
	            holder = new ItemHolder();
	            inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	            row = (FrameLayout) inflater.inflate(layoutResourceId, parent, false);
	            
	            /**
	             * You need to change this part, to load image from sd-card
	             */
	            //ImageView itemImage = (ImageView)row.findViewById(R.id.item_image);
	            //holder.itemImage = itemImage;
	        } else {
	            holder = (ItemHolder) row.getTag();
	        }

	        row.setTag(holder);
	       // setImageBitmap(item, holder.itemImage);
	        return row;
	    }

	    public static class ItemHolder
	    {
	        ImageView itemImage;
	    }

	    
	    // resize the image proportionately so it fits the entire space
	    private void setImageBitmap(int item, ImageView imageView){
	        Bitmap bitmap = BitmapFactory.decodeResource(getContext().getResources(),item);
	        float i = ((float) imageWidth) / ((float) bitmap.getWidth());
	        float imageHeight = i * (bitmap.getHeight());
	        FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) imageView.getLayoutParams();
	        params.height = (int) imageHeight;
	        params.width = (int) imageWidth;
	        imageView.setLayoutParams(params);
	        imageView.setImageResource(item);
	    }

	    public static float convertDpToPixel(float dp, Context context){
	        Resources resources = context.getResources();
	        DisplayMetrics metrics = resources.getDisplayMetrics();
	        float px = dp * (metrics.densityDpi/160f);
	        return px;
	    }

	}



That's basically it.


Thanks for your reply. I had already tried(changing the array adapter to string) what you have suggested but I am totally lost on how to change the path to set the images. You had specified the lines where I should assign the path but I am unable to put things together cause I am just a fresher. Any insights or a small example would help me a lot. Much obliged for your help.
Was This Post Helpful? 0
  • +
  • -

#6 EndLessMind  Icon User is offline

  • These are the droids you're looking for
  • member icon

Reputation: 194
  • View blog
  • Posts: 1,099
  • Joined: 13-March 09

Re: Unable to retreive images from a folder in Android

Posted 06 January 2014 - 01:11 PM

Oh, okay.
The stings you add to the adapter, will be the path of the file (the absolute path)
Then you just need this:
	    private void setImageBitmap(String filePath, ImageView imageView){
	        Bitmap bitmap = BitmapFactory.decodeFile(filePath); //This is what i've changed
	        float i = ((float) imageWidth) / ((float) bitmap.getWidth());
	        float imageHeight = i * (bitmap.getHeight());
	        FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) imageView.getLayoutParams();
	        params.height = (int) imageHeight;
	        params.width = (int) imageWidth;
	        imageView.setLayoutParams(params);
	        imageView.setImageResource(item);
	    }



And to get the absolute path, you'll need something like this:
public ArrayList<String> getImages() {
	//Create a File-object. This is where the images are located.
	File mainFolder = new File(String PATH = Environment.getExternalStorageDirectory() + "/Pictures/SanPics2/");
	//We need an array to storage the paths and return when we're done.
	ArraList<String> files = new ArrayList<String>();

	//If listFiles() returns null, then there is no images in that folder.
	if (mainFolder.listFiles() == null)
		return null;

	//Loop through each file in that folder and if it is and jpeg, then we'll add it's path to the array.
	for (File f : mainFolder.listFiles()) {
		if (f.getName().contains(".jpg")) {
			files.add(f.getAbsolutePath());
		}

	}
	/We're done, return that array of paths
	return files;

} 


This is just written from the top of my head, it where might be some minor errors (like typos)
But you just call that function when you want to get a list of all the images.
Then you add that list to the adapter.

This post has been edited by EndLessMind: 06 January 2014 - 01:15 PM

Was This Post Helpful? 1
  • +
  • -

#7 San T  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 04-January 14

Re: Unable to retreive images from a folder in Android

Posted 07 January 2014 - 09:33 PM

@EndLessMind Thanks for your reply. It helped a lot. I just wanna make sure whether the following line should be replaced :
 imageView.setImageResource(item);


with
 imageView.setImageBitmap(bitmap);

. Also that where I should call the getImages() method.

I believe that I should call the getImages() method somewhere in the setImageBitmap() method and pass the files to imageview. Please correct me if I am wrong. Also if,
 imageView.setImageResource(item);

would work, then what would be the value if item. Before, I would pass the value of item as a part of argument in setImageBitmap(). How would I do it now ?

P.S : I have successfully set the images from a specified path but I am able to do that for only one image.The code is as follows :

path = android.os.Environment.getExternalStorageDirectory() + File.separator + "Pictures" + File.separator + "SanPics2";
File file = new File(path,"Image 4.jpg");
String set_image = file.toString(); // This is where I have to specify the image name, if I give just the path then its empty; I mean no images are set in the screen.
Bitmap bitmap = BitmapFactory.decodeFile(set_image);
imageView.setImageBitmap(bitmap);




Thank you so much for taking the effort. Much appreciated.
Was This Post Helpful? 0
  • +
  • -

#8 EndLessMind  Icon User is offline

  • These are the droids you're looking for
  • member icon

Reputation: 194
  • View blog
  • Posts: 1,099
  • Joined: 13-March 09

Re: Unable to retreive images from a folder in Android

Posted 07 January 2014 - 10:50 PM

Quote

Thanks for your reply. It helped a lot. I just wanna make sure whether the following line should be replaced :
 imageView.setImageResource(item);


with
 imageView.setImageBitmap(bitmap);

.

Correct

Quote

Also that where I should call the getImages() method.

You can call this in the onCreate(), before you create the adapter.
The adapter should now hold the strings returned from getImages()
Was This Post Helpful? 0
  • +
  • -

#9 San T  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 04-January 14

Re: Unable to retreive images from a folder in Android

Posted 08 January 2014 - 01:05 AM

I am still not able to get the images despite trying your suggestions. I think I am missing something here. Please take a look at the code(only the vital part) below :

public class ItemsAdapter extends ArrayAdapter<String>{

    Context context; 
    LayoutInflater inflater;
    int layoutResourceId;
    float imageWidth;
    InputStream is;
    int item;
    public ItemsAdapter(Context context, int layoutResourceId, String[] items) {
        super(context, layoutResourceId, items);
        this.context = context;
        this.layoutResourceId = layoutResourceId;
        float width = ((Activity)context).getWindowManager().getDefaultDisplay().getWidth();
        float margin = (int)convertDpToPixel(10f, (Activity)context);
        imageWidth = ((width - (3 * margin)) / 2);
        
    }

	@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        FrameLayout row = (FrameLayout) convertView;
        ItemHolder holder;
        String item = getItem(position);
        if (row == null) {
			holder = new ItemHolder();
            inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            row = (FrameLayout) inflater.inflate(layoutResourceId, parent, false);
            ImageView itemImage = (ImageView)row.findViewById(R.id.item_image);
			holder.itemImage = itemImage;
		} else {
			holder = (ItemHolder) row.getTag();
		}
		row.setTag(holder);
		setImageBitmap(item, holder.itemImage);
        return row;
    }

    public static class ItemHolder
    {
    	ImageView itemImage;
    }
	
    // resize the image proportionately so it fits the entire space
	private void setImageBitmap(String path, ImageView imageView){
		path = android.os.Environment.getExternalStorageDirectory() + File.separator + "Pictures" + File.separator + "SanPics2";
		Bitmap bitmap = BitmapFactory.decodeFile(path);
		float i = ((float) imageWidth) / ((float) bitmap.getWidth());
		float imageHeight = i * (bitmap.getHeight());
		FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) imageView.getLayoutParams();
		params.height = (int) imageHeight;
		params.width = (int) imageWidth;
		imageView.setLayoutParams(params);
		/*int count = 10;
		String file_name = null;
		for(int j = 1;j<count;j++)
		{
			 file_name = "Image " + i + ".jpg";
		}*/
		imageView.setImageBitmap(bitmap);
		
	}
public ArrayList<String> getImages()
	{
		String path = android.os.Environment.getExternalStorageDirectory() + "/Pictures/SanPics2/";
		File mainfolder = new File(path);
		ArrayList<String> files = new ArrayList<String>();
		if(mainfolder.listFiles() == null)
		return null;
		for(File f : mainfolder.listFiles())
		{
			if(f.getName().contains(".jpg"))
			{
				files.add(f.getAbsolutePath());
			}
		}
		return files;
	}



And the part where I am calling the ItemsAdapter class is as follows :

private void loadItems(){
		String path = android.os.Environment.getExternalStorageDirectory() + File.separator + "Pictures" + File.separator + "SanPics2";
		File file = new File(path,"Image 4.jpg");
		String image_name = file.toString();;
		String[] leftItems = new String[]{image_name,image_name,image_name,image_name};
		String[] rightItems = new String[]{image_name,image_name,image_name,image_name};
		leftAdapter = new ItemsAdapter(this, R.layout.item, leftItems);
		rightAdapter = new ItemsAdapter(this, R.layout.item, rightItems);
		listViewLeft.setAdapter(leftAdapter);
		listViewRight.setAdapter(rightAdapter);
		leftViewsHeights = new int[leftItems.length];
		rightViewsHeights = new int[rightItems.length];	
	}




I know that the content of the leftItems and rightItems doesn't mean anything and the main part is played by setImageBitmap() method in ItemsAdapter class.

Whenever I try the above code, no images are set in the image view and its empty. I believe that I am missing something here but just not sure where and what. It would really mean me a lot if you to give some insights.
Was This Post Helpful? 0
  • +
  • -

#10 EndLessMind  Icon User is offline

  • These are the droids you're looking for
  • member icon

Reputation: 194
  • View blog
  • Posts: 1,099
  • Joined: 13-March 09

Re: Unable to retreive images from a folder in Android

Posted 08 January 2014 - 01:12 AM

Okay, let's try changing the adapter to this:

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;



	public class ItemsAdapter extends ArrayAdapter<String>{

	    Context context; 
	    LayoutInflater inflater;
	    int layoutResourceId;
	    float imageWidth;
		ArrayList<String> strings;

	    public ItemsAdapter(Context context, int layoutResourceId, ArrayList<String> items) {
	        super(context, layoutResourceId, items);
	        this.context = context;
	        this.layoutResourceId = layoutResourceId;
			this.strings = items;
	        float width = ((Activity)context).getWindowManager().getDefaultDisplay().getWidth();
	        float margin = (int)convertDpToPixel(10f, (Activity)context);
	        // two images, three margins of 10dips
	        imageWidth = ((width - (3 * margin)) / 2);
	    }


	    @Override
	    public View getView(int position, View convertView, ViewGroup parent) {
	        FrameLayout row = (FrameLayout) convertView;
	        ItemHolder holder;
	        
	        String item = strings.get(position);

	        if (row == null) {
	            holder = new ItemHolder();
	            inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	            row = (FrameLayout) inflater.inflate(layoutResourceId, parent, false);
	            
	            ImageView itemImage = (ImageView)row.findViewById(R.id.item_image);
	            holder.itemImage = itemImage;
	        } else {
	            holder = (ItemHolder) row.getTag();
	        }

	        row.setTag(holder);
	        setImageBitmap(item, holder.itemImage);
	        return row;
	    }

	    public static class ItemHolder
	    {
	        ImageView itemImage;
	    }

	    
	    // resize the image proportionately so it fits the entire space
	private void setImageBitmap(String filePath, ImageView imageView){
    	Bitmap bitmap = BitmapFactory.decodeFile(filePath); //This is what i've changed
    	float i = ((float) imageWidth) / ((float) bitmap.getWidth());
    	float imageHeight = i * (bitmap.getHeight());
    	FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) imageView.getLayoutParams();
    	params.height = (int) imageHeight;
    	params.width = (int) imageWidth;
    	imageView.setLayoutParams(params);
    	imageView.setImageBitmap(bitmap);
	}



	    public static float convertDpToPixel(float dp, Context context){
	        Resources resources = context.getResources();
	        DisplayMetrics metrics = resources.getDisplayMetrics();
	        float px = dp * (metrics.densityDpi/160f);
	        return px;
	    }

	}



Then when you create the adapter, so something like this:
mAdapter = new ItemsAdapter(this, R.layout.item, getImages());

That should work
Was This Post Helpful? 0
  • +
  • -

#11 San T  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 04-January 14

Re: Unable to retreive images from a folder in Android

Posted 08 January 2014 - 04:28 AM

View PostEndLessMind, on 08 January 2014 - 01:12 AM, said:

Okay, let's try changing the adapter to this:

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;



	public class ItemsAdapter extends ArrayAdapter<String>{

	    Context context; 
	    LayoutInflater inflater;
	    int layoutResourceId;
	    float imageWidth;
		ArrayList<String> strings;

	    public ItemsAdapter(Context context, int layoutResourceId, ArrayList<String> items) {
	        super(context, layoutResourceId, items);
	        this.context = context;
	        this.layoutResourceId = layoutResourceId;
			this.strings = items;
	        float width = ((Activity)context).getWindowManager().getDefaultDisplay().getWidth();
	        float margin = (int)convertDpToPixel(10f, (Activity)context);
	        // two images, three margins of 10dips
	        imageWidth = ((width - (3 * margin)) / 2);
	    }


	    @Override
	    public View getView(int position, View convertView, ViewGroup parent) {
	        FrameLayout row = (FrameLayout) convertView;
	        ItemHolder holder;
	        
	        String item = strings.get(position);

	        if (row == null) {
	            holder = new ItemHolder();
	            inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	            row = (FrameLayout) inflater.inflate(layoutResourceId, parent, false);
	            
	            ImageView itemImage = (ImageView)row.findViewById(R.id.item_image);
	            holder.itemImage = itemImage;
	        } else {
	            holder = (ItemHolder) row.getTag();
	        }

	        row.setTag(holder);
	        setImageBitmap(item, holder.itemImage);
	        return row;
	    }

	    public static class ItemHolder
	    {
	        ImageView itemImage;
	    }

	    
	    // resize the image proportionately so it fits the entire space
	private void setImageBitmap(String filePath, ImageView imageView){
    	Bitmap bitmap = BitmapFactory.decodeFile(filePath); //This is what i've changed
    	float i = ((float) imageWidth) / ((float) bitmap.getWidth());
    	float imageHeight = i * (bitmap.getHeight());
    	FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) imageView.getLayoutParams();
    	params.height = (int) imageHeight;
    	params.width = (int) imageWidth;
    	imageView.setLayoutParams(params);
    	imageView.setImageBitmap(bitmap);
	}



	    public static float convertDpToPixel(float dp, Context context){
	        Resources resources = context.getResources();
	        DisplayMetrics metrics = resources.getDisplayMetrics();
	        float px = dp * (metrics.densityDpi/160f);
	        return px;
	    }

	}



Then when you create the adapter, so something like this:
mAdapter = new ItemsAdapter(this, R.layout.item, getImages());

That should work


It is actually really good what you said about changing the parameters and using it. It all makes clear sense on how the files are retrieved and passed into the adapter but still I am not getting anything on the screen. getImages() retrieves all the images from my folder, thanks to you but why is it not setting in the adapter is what amuses me ! I can post in the entire code if you wish to see and resolve it. It would mean a lot, thanks.
Was This Post Helpful? 0
  • +
  • -

#12 EndLessMind  Icon User is offline

  • These are the droids you're looking for
  • member icon

Reputation: 194
  • View blog
  • Posts: 1,099
  • Joined: 13-March 09

Re: Unable to retreive images from a folder in Android

Posted 08 January 2014 - 05:15 PM

Yes, please post the entire code :)
Was This Post Helpful? 0
  • +
  • -

#13 San T  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 04-January 14

Re: Unable to retreive images from a folder in Android

Posted 08 January 2014 - 09:28 PM

View PostEndLessMind, on 08 January 2014 - 05:15 PM, said:

Yes, please post the entire code :)/>


ItemsActivity.java :

package com.vladimir.pinterestlistview;

import java.io.File;
import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.AbsListView;
import android.widget.AbsListView.onscrollListener;
import android.widget.ListView;

import com.vladimir.pinterestlistview.adapters.ItemsAdapter;

public class ItemsActivity extends Activity {
	
	private ListView listViewLeft;
	private ListView listViewRight;
	private ItemsAdapter leftAdapter;
	private ItemsAdapter rightAdapter;

	int[] leftViewsHeights;
	int[] rightViewsHeights;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.items_list);	
		
		listViewLeft = (ListView) findViewById(R.id.list_view_left);
		listViewRight = (ListView) findViewById(R.id.list_view_right);
		//ItemsAdapter ia = null;
		//ArrayList<String> image = ia.getImages();
		
		loadItems();
		
		listViewLeft.setOnTouchListener(touchListener);
		listViewRight.setOnTouchListener(touchListener);		
		listViewLeft.setonscrollListener(scrollListener);
		listViewRight.setonscrollListener(scrollListener);
	}
	
	// Passing the touch event to the opposite list
	OnTouchListener touchListener = new OnTouchListener() {					
		boolean dispatched = false;
		
		@Override
		public boolean onTouch(View v, MotionEvent event) {
			if (v.equals(listViewLeft) && !dispatched) {
				dispatched = true;
				listViewRight.dispatchTouchEvent(event);
			} else if (v.equals(listViewRight) && !dispatched) {
				dispatched = true;
				listViewLeft.dispatchTouchEvent(event);
			}
			
			dispatched = false;
			return false;
		}
	};
	
	/**
	 * Synchronizing scrolling 
	 * Distance from the top of the first visible element opposite list:
	 * sum_heights(opposite invisible screens) - sum_heights(invisible screens) + distance from top of the first visible child
	 */
	onscrollListener scrollListener = new onscrollListener() {
		
		@Override
		public void onscrollStateChanged(AbsListView v, int scrollState) {	
		}
		
		@Override
		public void onscroll(AbsListView view, int firstVisibleItem,
				int visibleItemCount, int totalItemCount) {
			
			if (view.getChildAt(0) != null) {
				if (view.equals(listViewLeft) ){
					leftViewsHeights[view.getFirstVisiblePosition()] = view.getChildAt(0).getHeight();
					
					int h = 0;
					for (int i = 0; i < listViewRight.getFirstVisiblePosition(); i++) {
						h += rightViewsHeights[i];
					}
					
					int hi = 0;
					for (int i = 0; i < listViewLeft.getFirstVisiblePosition(); i++) {
						hi += leftViewsHeights[i];
					}
					
					int top = h - hi + view.getChildAt(0).getTop();
					listViewRight.setSelectionFromTop(listViewRight.getFirstVisiblePosition(), top);
				} else if (view.equals(listViewRight)) {
					rightViewsHeights[view.getFirstVisiblePosition()] = view.getChildAt(0).getHeight();
					
					int h = 0;
					for (int i = 0; i < listViewLeft.getFirstVisiblePosition(); i++) {
						h += leftViewsHeights[i];
					}
					
					int hi = 0;
					for (int i = 0; i < listViewRight.getFirstVisiblePosition(); i++) {
						hi += rightViewsHeights[i];
					}
					
					int top = h - hi + view.getChildAt(0).getTop();
					listViewLeft.setSelectionFromTop(listViewLeft.getFirstVisiblePosition(), top);
				}
				
			}
			
		}
	};
	
		private void loadItems(){
			/*String path = android.os.Environment.getExternalStorageDirectory() + File.separator + "Pictures" + File.separator + "SanPics2";
			File file = new File(path,"Image 4.jpg");
			String image_name = file.toString();*/
			String[] leftItems = new String[]{};
			String[] rightItems = new String[]{};
			ItemsAdapter mAdapter = null;
			ArrayList<String> image_items = ItemsAdapter.getImages(); 
			System.out.println("The images are got in image_items");
			System.out.println("The list of images are" + image_items.toString());
			mAdapter = new ItemsAdapter(this,R.layout.item,image_items);
			listViewLeft.setAdapter(mAdapter);
			listViewRight.setAdapter(mAdapter);
			leftViewsHeights = new int[leftItems.length];
			rightViewsHeights = new int[rightItems.length];	
		}


}



ItemsAdapter.java

import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;
import com.vladimir.pinterestlistview.R;

public class ItemsAdapter extends ArrayAdapter<String>{

    Context context; 
    LayoutInflater inflater;
    int layoutResourceId;
    float imageWidth;
    InputStream is;
    int item;
    public ItemsAdapter(Context context, int layoutResourceId, ArrayList<String> items) {
        super(context, layoutResourceId, items);
        this.context = context;
        this.layoutResourceId = layoutResourceId;
        float width = ((Activity)context).getWindowManager().getDefaultDisplay().getWidth();
        float margin = (int)convertDpToPixel(10f, (Activity)context);
        imageWidth = ((width - (3 * margin)) / 2);
        
    }

	@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        FrameLayout row = (FrameLayout) convertView;
        ItemHolder holder;
        String item = getItem(position);
        if (row == null) {
			holder = new ItemHolder();
            inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            row = (FrameLayout) inflater.inflate(layoutResourceId, parent, false);
            ImageView itemImage = (ImageView)row.findViewById(R.id.item_image);
			holder.itemImage = itemImage;
		} else {
			holder = (ItemHolder) row.getTag();
		}
		row.setTag(holder);
		setImageBit(item, holder.itemImage);
        return row;
    }

    public static class ItemHolder
    {
    	ImageView itemImage;
    }
	
    // resize the image proportionately so it fits the entire space
	private void setImageBit(String path, ImageView imageView){
		path = android.os.Environment.getExternalStorageDirectory() + File.separator + "Pictures" + File.separator + "SanPics2";
		Bitmap bitmap = BitmapFactory.decodeFile(path);
		float i = ((float) imageWidth) / ((float) bitmap.getWidth());
		float imageHeight = i * (bitmap.getHeight());
		FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) imageView.getLayoutParams();
		params.height = (int) imageHeight;
		params.width = (int) imageWidth;
		imageView.setLayoutParams(params);
		/*int count = 10;
		String file_name = null;
		for(int j = 1;j<count;j++)
		{
			 file_name = "Image " + i + ".jpg";
		}
		ArrayList<String> img_bitmap;
		Bitmap bmp = ImgBitFromFile(path, file_name);*/
		imageView.setImageBitmap(bitmap);
		
	}
	
	public static float convertDpToPixel(float dp, Context context){
	    Resources resources = context.getResources();
	    DisplayMetrics metrics = resources.getDisplayMetrics();
	    float px = dp * (metrics.densityDpi/160f);
	    return px;
	}
	public static ArrayList<String> getImages()
	{
		String path = android.os.Environment.getExternalStorageDirectory() + File.separator +  "Pictures" + File.separator + "SanPics2";
		File mainfolder = new File(path);
		ArrayList<String> files = new ArrayList<String>();
		if(mainfolder.listFiles() == null)
		return null;
		for(File f : mainfolder.listFiles())
		{
			if(f.getName().contains(".jpg"))
			{
				files.add(f.getAbsolutePath());
			}
		}
		return files;
	}
}



The problem is somewhere in ItemsAdapter.java and I am able to retrieve the list of images from my folder as it is evident from my logcat(i am printing the files). I have also attached the log cat for your reference.

Log cat :

01-09 09:55:52.450: E/Trace(11191): error opening trace file: No such file or directory (2)
01-09 09:55:52.510: V/ActivityThread(11191): Class path: /data/app/com.vladimir.pinterestlistview-1.apk, JNI path: /data/data/com.vladimir.pinterestlistview/lib
01-09 09:55:52.710: I/System.out(11191): The images are got in image_items
01-09 09:55:52.710: I/System.out(11191): The list of images are[/storage/sdcard0/Pictures/SanPics2/Image 7.jpg, /storage/sdcard0/Pictures/SanPics2/Image 1.jpg, /storage/sdcard0/Pictures/SanPics2/Image 2.jpg, /storage/sdcard0/Pictures/SanPics2/Image 3.jpg, /storage/sdcard0/Pictures/SanPics2/Image 4.jpg, /storage/sdcard0/Pictures/SanPics2/Image 5.jpg, /storage/sdcard0/Pictures/SanPics2/Image 8.jpg, /storage/sdcard0/Pictures/SanPics2/1388143033275.jpg, /storage/sdcard0/Pictures/SanPics2/1388143591263.jpg, /storage/sdcard0/Pictures/SanPics2/1388143312172.jpg, /storage/sdcard0/Pictures/SanPics2/1388143530089.jpg, /storage/sdcard0/Pictures/SanPics2/Image 6.jpg]
01-09 09:55:52.890: I/Adreno200-EGL(11191): <qeglDrvAPI_eglInitialize:299>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_JB_REL_2.0.3_RB3.04.01.01.42.002_msm8625_JB_REL_2.0.3_Merge_release_AU (Merge)
01-09 09:55:52.890: I/Adreno200-EGL(11191): Build Date: 12/12/12 Wed
01-09 09:55:52.890: I/Adreno200-EGL(11191): Local Branch:
01-09 09:55:52.890: I/Adreno200-EGL(11191): Remote Branch: m/jb_rel_2.0.3
01-09 09:55:52.890: I/Adreno200-EGL(11191): Local Patches: NONE
01-09 09:55:52.890: I/Adreno200-EGL(11191): Reconstruct Branch: AU_LINUX_ANDROID_JB_REL_2.0.3_RB3.04.01.01.42.002 + NOTHING
01-09 09:55:52.990: E/ViewRootImpl(11191): performLayout : host is null
01-09 09:55:53.020: E/ViewRootImpl(11191): performLayout : host is null
01-09 09:55:53.020: D/HardwareRenderer(11191): draw surface is valid dirty= Rect(0, 0 - 480, 800)
01-09 09:56:08.070: D/HardwareRenderer(11191): draw surface is valid dirty= Rect(0, 0 - 480, 800)
01-09 09:56:14.180: D/HardwareRenderer(11191): draw surface is valid dirty= Rect(15, 110 - 240, 800)
01-09 09:56:15.870: D/HardwareRenderer(11191): draw surface is valid dirty= Rect(15, 110 - 240, 800)

The "draw surface statement .." repeats itself when I touch the screen but nothing happens other than that.

Finally, thanks for taking a look at my code. It means a lot. Keep that spirit up.

View PostEndLessMind, on 08 January 2014 - 05:15 PM, said:

Yes, please post the entire code :)/>


ItemsActivity.java :

package com.vladimir.pinterestlistview;

import java.io.File;
import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.AbsListView;
import android.widget.AbsListView.onscrollListener;
import android.widget.ListView;

import com.vladimir.pinterestlistview.adapters.ItemsAdapter;

public class ItemsActivity extends Activity {
	
	private ListView listViewLeft;
	private ListView listViewRight;
	private ItemsAdapter leftAdapter;
	private ItemsAdapter rightAdapter;

	int[] leftViewsHeights;
	int[] rightViewsHeights;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.items_list);	
		
		listViewLeft = (ListView) findViewById(R.id.list_view_left);
		listViewRight = (ListView) findViewById(R.id.list_view_right);
		//ItemsAdapter ia = null;
		//ArrayList<String> image = ia.getImages();
		
		loadItems();
		
		listViewLeft.setOnTouchListener(touchListener);
		listViewRight.setOnTouchListener(touchListener);		
		listViewLeft.setonscrollListener(scrollListener);
		listViewRight.setonscrollListener(scrollListener);
	}
	
	// Passing the touch event to the opposite list
	OnTouchListener touchListener = new OnTouchListener() {					
		boolean dispatched = false;
		
		@Override
		public boolean onTouch(View v, MotionEvent event) {
			if (v.equals(listViewLeft) && !dispatched) {
				dispatched = true;
				listViewRight.dispatchTouchEvent(event);
			} else if (v.equals(listViewRight) && !dispatched) {
				dispatched = true;
				listViewLeft.dispatchTouchEvent(event);
			}
			
			dispatched = false;
			return false;
		}
	};
	
	/**
	 * Synchronizing scrolling 
	 * Distance from the top of the first visible element opposite list:
	 * sum_heights(opposite invisible screens) - sum_heights(invisible screens) + distance from top of the first visible child
	 */
	onscrollListener scrollListener = new onscrollListener() {
		
		@Override
		public void onscrollStateChanged(AbsListView v, int scrollState) {	
		}
		
		@Override
		public void onscroll(AbsListView view, int firstVisibleItem,
				int visibleItemCount, int totalItemCount) {
			
			if (view.getChildAt(0) != null) {
				if (view.equals(listViewLeft) ){
					leftViewsHeights[view.getFirstVisiblePosition()] = view.getChildAt(0).getHeight();
					
					int h = 0;
					for (int i = 0; i < listViewRight.getFirstVisiblePosition(); i++) {
						h += rightViewsHeights[i];
					}
					
					int hi = 0;
					for (int i = 0; i < listViewLeft.getFirstVisiblePosition(); i++) {
						hi += leftViewsHeights[i];
					}
					
					int top = h - hi + view.getChildAt(0).getTop();
					listViewRight.setSelectionFromTop(listViewRight.getFirstVisiblePosition(), top);
				} else if (view.equals(listViewRight)) {
					rightViewsHeights[view.getFirstVisiblePosition()] = view.getChildAt(0).getHeight();
					
					int h = 0;
					for (int i = 0; i < listViewLeft.getFirstVisiblePosition(); i++) {
						h += leftViewsHeights[i];
					}
					
					int hi = 0;
					for (int i = 0; i < listViewRight.getFirstVisiblePosition(); i++) {
						hi += rightViewsHeights[i];
					}
					
					int top = h - hi + view.getChildAt(0).getTop();
					listViewLeft.setSelectionFromTop(listViewLeft.getFirstVisiblePosition(), top);
				}
				
			}
			
		}
	};
	
		private void loadItems(){
			/*String path = android.os.Environment.getExternalStorageDirectory() + File.separator + "Pictures" + File.separator + "SanPics2";
			File file = new File(path,"Image 4.jpg");
			String image_name = file.toString();*/
			String[] leftItems = new String[]{};
			String[] rightItems = new String[]{};
			ItemsAdapter mAdapter = null;
			ArrayList<String> image_items = ItemsAdapter.getImages(); 
			System.out.println("The images are got in image_items");
			System.out.println("The list of images are" + image_items.toString());
			mAdapter = new ItemsAdapter(this,R.layout.item,image_items);
			listViewLeft.setAdapter(mAdapter);
			listViewRight.setAdapter(mAdapter);
			leftViewsHeights = new int[leftItems.length];
			rightViewsHeights = new int[rightItems.length];	
		}


}



ItemsAdapter.java

import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;
import com.vladimir.pinterestlistview.R;

public class ItemsAdapter extends ArrayAdapter<String>{

    Context context; 
    LayoutInflater inflater;
    int layoutResourceId;
    float imageWidth;
    InputStream is;
    int item;
    public ItemsAdapter(Context context, int layoutResourceId, ArrayList<String> items) {
        super(context, layoutResourceId, items);
        this.context = context;
        this.layoutResourceId = layoutResourceId;
        float width = ((Activity)context).getWindowManager().getDefaultDisplay().getWidth();
        float margin = (int)convertDpToPixel(10f, (Activity)context);
        imageWidth = ((width - (3 * margin)) / 2);
        
    }

	@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        FrameLayout row = (FrameLayout) convertView;
        ItemHolder holder;
        String item = getItem(position);
        if (row == null) {
			holder = new ItemHolder();
            inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            row = (FrameLayout) inflater.inflate(layoutResourceId, parent, false);
            ImageView itemImage = (ImageView)row.findViewById(R.id.item_image);
			holder.itemImage = itemImage;
		} else {
			holder = (ItemHolder) row.getTag();
		}
		row.setTag(holder);
		setImageBit(item, holder.itemImage);
        return row;
    }

    public static class ItemHolder
    {
    	ImageView itemImage;
    }
	
    // resize the image proportionately so it fits the entire space
	private void setImageBit(String path, ImageView imageView){
		path = android.os.Environment.getExternalStorageDirectory() + File.separator + "Pictures" + File.separator + "SanPics2";
		Bitmap bitmap = BitmapFactory.decodeFile(path);
		float i = ((float) imageWidth) / ((float) bitmap.getWidth());
		float imageHeight = i * (bitmap.getHeight());
		FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) imageView.getLayoutParams();
		params.height = (int) imageHeight;
		params.width = (int) imageWidth;
		imageView.setLayoutParams(params);
		/*int count = 10;
		String file_name = null;
		for(int j = 1;j<count;j++)
		{
			 file_name = "Image " + i + ".jpg";
		}
		ArrayList<String> img_bitmap;
		Bitmap bmp = ImgBitFromFile(path, file_name);*/
		imageView.setImageBitmap(bitmap);
		
	}
	
	public static float convertDpToPixel(float dp, Context context){
	    Resources resources = context.getResources();
	    DisplayMetrics metrics = resources.getDisplayMetrics();
	    float px = dp * (metrics.densityDpi/160f);
	    return px;
	}
	public static ArrayList<String> getImages()
	{
		String path = android.os.Environment.getExternalStorageDirectory() + File.separator +  "Pictures" + File.separator + "SanPics2";
		File mainfolder = new File(path);
		ArrayList<String> files = new ArrayList<String>();
		if(mainfolder.listFiles() == null)
		return null;
		for(File f : mainfolder.listFiles())
		{
			if(f.getName().contains(".jpg"))
			{
				files.add(f.getAbsolutePath());
			}
		}
		return files;
	}
}



The problem is somewhere in ItemsAdapter.java and I am able to retrieve the list of images from my folder as it is evident from my logcat(i am printing the files). I have also attached the log cat for your reference.

Log cat :

01-09 09:55:52.450: E/Trace(11191): error opening trace file: No such file or directory (2)
01-09 09:55:52.510: V/ActivityThread(11191): Class path: /data/app/com.vladimir.pinterestlistview-1.apk, JNI path: /data/data/com.vladimir.pinterestlistview/lib
01-09 09:55:52.710: I/System.out(11191): The images are got in image_items
01-09 09:55:52.710: I/System.out(11191): The list of images are[/storage/sdcard0/Pictures/SanPics2/Image 7.jpg, /storage/sdcard0/Pictures/SanPics2/Image 1.jpg, /storage/sdcard0/Pictures/SanPics2/Image 2.jpg, /storage/sdcard0/Pictures/SanPics2/Image 3.jpg, /storage/sdcard0/Pictures/SanPics2/Image 4.jpg, /storage/sdcard0/Pictures/SanPics2/Image 5.jpg, /storage/sdcard0/Pictures/SanPics2/Image 8.jpg, /storage/sdcard0/Pictures/SanPics2/1388143033275.jpg, /storage/sdcard0/Pictures/SanPics2/1388143591263.jpg, /storage/sdcard0/Pictures/SanPics2/1388143312172.jpg, /storage/sdcard0/Pictures/SanPics2/1388143530089.jpg, /storage/sdcard0/Pictures/SanPics2/Image 6.jpg]
01-09 09:55:52.890: I/Adreno200-EGL(11191): <qeglDrvAPI_eglInitialize:299>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_JB_REL_2.0.3_RB3.04.01.01.42.002_msm8625_JB_REL_2.0.3_Merge_release_AU (Merge)
01-09 09:55:52.890: I/Adreno200-EGL(11191): Build Date: 12/12/12 Wed
01-09 09:55:52.890: I/Adreno200-EGL(11191): Local Branch:
01-09 09:55:52.890: I/Adreno200-EGL(11191): Remote Branch: m/jb_rel_2.0.3
01-09 09:55:52.890: I/Adreno200-EGL(11191): Local Patches: NONE
01-09 09:55:52.890: I/Adreno200-EGL(11191): Reconstruct Branch: AU_LINUX_ANDROID_JB_REL_2.0.3_RB3.04.01.01.42.002 + NOTHING
01-09 09:55:52.990: E/ViewRootImpl(11191): performLayout : host is null
01-09 09:55:53.020: E/ViewRootImpl(11191): performLayout : host is null
01-09 09:55:53.020: D/HardwareRenderer(11191): draw surface is valid dirty= Rect(0, 0 - 480, 800)
01-09 09:56:08.070: D/HardwareRenderer(11191): draw surface is valid dirty= Rect(0, 0 - 480, 800)
01-09 09:56:14.180: D/HardwareRenderer(11191): draw surface is valid dirty= Rect(15, 110 - 240, 800)
01-09 09:56:15.870: D/HardwareRenderer(11191): draw surface is valid dirty= Rect(15, 110 - 240, 800)

The "draw surface statement .." repeats itself when I touch the screen but nothing happens other than that.

Finally, thanks for taking a look at my code. It means a lot. Keep that spirit up.
Was This Post Helpful? 0
  • +
  • -

#14 EndLessMind  Icon User is offline

  • These are the droids you're looking for
  • member icon

Reputation: 194
  • View blog
  • Posts: 1,099
  • Joined: 13-March 09

Re: Unable to retreive images from a folder in Android

Posted 09 January 2014 - 03:08 AM

First, getImages should be in the the activity, not in the adatper :P But it's not the cause of your problem.

Also, in setImageBit, you change the path of the images to "/sdcard/Pictures/SanPics2/" with
path = android.os.Environment.getExternalStorageDirectory() + File.separator + "Pictures" + File.separator + "SanPics2"
So, comment it out. I think that is the cause of your problem. :P
Was This Post Helpful? 0
  • +
  • -

#15 San T  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 04-January 14

Re: Unable to retreive images from a folder in Android

Posted 09 January 2014 - 03:12 AM

View PostEndLessMind, on 09 January 2014 - 03:08 AM, said:

First, getImages should be in the the activity, not in the adatper :P/> But it's not the cause of your problem.

Also, in setImageBit, you change the path of the images to "/sdcard/Pictures/SanPics2/" with
path = android.os.Environment.getExternalStorageDirectory() + File.separator + "Pictures" + File.separator + "SanPics2"
So, comment it out. I think that is the cause of your problem. :P/>


But that is the path of my image folder,if I comment it then how will it identify the path ??!!
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3