How to load all image from sdcard specific folder to display

All your problems with Audio, Video and Images.

How to load all image from sdcard specific folder to display

Postby tanijung » Tue Jul 12, 2011 2:43 pm

How all to load image from sdcard specific folder to display in gridview
tanijung
Freshman
Freshman
 
Posts: 4
Joined: Mon Jul 04, 2011 6:09 am

Top

Re: How to load all image from sdcard specific folder to dis

Postby adidmafioso » Wed Jul 13, 2011 8:05 am

use the below code nad revert if it helps

public class SdcardImageDispaly extends Activity
{
public Bitmap bitMap;
/**
* Cursor used to access the results from querying for images on the SD card.
*/
private Cursor cursor;
/*
* Column index for the Thumbnails Image IDs.
*/
private int columnIndex;

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

// Set up an array of the Thumbnail Image ID column we want
String[] projection = {BaseColumns._ID};
// Create the cursor pointing to the SDCard
cursor = managedQuery( MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
projection, // Which columns to return
null, // Return all rows
null,MediaStore.Images.Thumbnails.IMAGE_ID);
// Get the column index of the Thumbnails Image ID
columnIndex = cursor.getColumnIndexOrThrow(BaseColumns._ID);

GridView sdcardImages = (GridView) findViewById(R.id.sdcard);
sdcardImages.setAdapter(new ImageAdapter(this));
// Set up a click listener
sdcardImages.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position, long id) {
// Get the data location of the image
String[] projection = {MediaColumns.DATA};
cursor = managedQuery( MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
projection, // Which columns to return
null, // Return all rows
null,null);
columnIndex = cursor.getColumnIndexOrThrow(MediaColumns.DATA);
cursor.moveToPosition(position);
// Get image filename
String imagePath = cursor.getString(columnIndex);
Log.e("imagepath",""+imagePath);
File imageFile = new File(imagePath);
if(imageFile.exists())
{
//load the bitmap from the given path
Log.e("iamge file exists",""+imagePath);
//bitMap= BitmapFactory.decodeFile(imagePath);
Intent intent = new Intent(getApplicationContext(),Registration.class);
intent.putExtra("imagePath", imagePath);
Log.e("b4 setresulr",""+imagePath);
setResult(RESULT_OK,intent);
Log.e("after result",""+imagePath);
finish();
}
/*Intent sendpicture=new Intent(getApplicationContext(),UserDetail.class);
sendpicture.putExtra("sendpicture",""+imagePath);
startActivityForResult(sendpicture,0);
finish();*/
// Use this path to do further processing, i.e. full screen display
}
});
}

/**
* Adapter for our image files.
*/
private class ImageAdapter extends BaseAdapter
{
private Context context;

public ImageAdapter(Context localContext)
{
context = localContext;
}
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 picturesView;
if (convertView == null) {
picturesView = new ImageView(context);
// Move cursor to current position
cursor.moveToPosition(position);
// Get the current value for the requested column
int imageID = cursor.getInt(columnIndex);
// Set the content of the image based on the provided URI
picturesView.setImageURI(Uri.withAppendedPath(
MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, "" + imageID));
picturesView.setScaleType(ImageView.ScaleType.FIT_CENTER);
picturesView.setPadding(8, 8, 8, 8);
picturesView.setLayoutParams(new GridView.LayoutParams(100, 100));
}
else {
picturesView = (ImageView)convertView;
}
return picturesView;
}
}
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if ((keyCode == KeyEvent.KEYCODE_BACK))
{

Log.d(this.getClass().getName(), "back button pressed");
}
return super.onKeyDown(keyCode, event);
}
}
adidmafioso
Developer
Developer
 
Posts: 33
Joined: Mon Sep 21, 2009 9:30 pm
Location: delhi

Re: How to load all image from sdcard specific folder to dis

Postby adidmafioso » Wed Jul 13, 2011 8:07 am

below is the layout for above sdcard.alyout

<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/sdcard"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:numColumns="auto_fit"
android:columnWidth="90dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>
adidmafioso
Developer
Developer
 
Posts: 33
Joined: Mon Sep 21, 2009 9:30 pm
Location: delhi

Re: How to load all image from sdcard specific folder to dis

Postby tanijung » Thu Jul 14, 2011 12:40 pm

Thank you very much ^__^
tanijung
Freshman
Freshman
 
Posts: 4
Joined: Mon Jul 04, 2011 6:09 am

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 6 guests