2016-03-17 3 views
0

Я хочу установить личные изображения в drawable.Как установить путь к каталогу

package info.androidhive.imageslider.helper; 

import java.util.Arrays; 
import java.util.List; 

public class AppConstant { 

// Number of columns of Grid View 
public static final int NUM_OF_COLUMNS = 3; 

// Gridview image padding 
public static final int GRID_PADDING = 8; // in dp 

// SD card image directory 
public static final String PHOTO_ALBUM = "NAT"; 
public static final String PHOTO_ALBUM =Environment.getExternalStorageDirectory().getPath()+ "/DCIM/"+"/100ANDRO/"; 

// supported file formats list 
public static final List<String> FILE_EXTN = Arrays.asList("jpg", "jpeg", 
     "png"); 
} 
+0

исправить ваше сообщение форматирования сначала –

ответ

0

Попробуйте:

String PHOTO_ALBUM =Environment.getExternalStorageDirectory().getPath()+ "/DCIM/"+"/100ANDRO/"; 
File f = new File(PHOTO_ALBUM);   
File file[] = f.listFiles(); 
for (int i=0; i < file.length; i++) 
{ 
    String file_extension=file[i].getName().split("."); 
    if(file_extension[file_extension.length-1].equalsIgnoreCase("jpg")) 
    { 
    // code here set image to imageview 
     Bitmap bmp = BitmapFactory.decodeFile(file[i]); 
     //ImageView img; 
     //img.setImageBitmap(bmp); 
    } 
    else if(file_extension[file_extension.length-1].equalsIgnoreCase("png")) 
    { 
    // code here set image to imageview 
    } 
    //.. so on 
} 

Добавить разрешение на чтение Внешние устройства хранения

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> 
1

Попробуйте как этот

public class PicAdapter extends BaseAdapter { //use the default gallery background image int defaultItemBackground; //gallery context private Context galleryContext; //array to store bitmaps to display private Bitmap[] imageBitmaps; //placeholder bitmap for empty spaces in gallery Bitmap placeholder; //constructor public PicAdapter(Context c) { //instantiate context galleryContext = c; //create bitmap array String folderPath = Environment.getExternalStorageDirectory() + "/DCIM/"+"/100ANDRO/"; File filePath = new File(folderPath); File[] fileList = filePath.listFiles(); imageBitmaps = new Bitmap[fileList.length]; for(int j = 0; j < fileList.length; j++) { imageBitmaps[j] = BitmapFactory.decodeFile(fileList[j].toString()); } //System.out.println("==styleCode==" + styleCode + "=strExecutive="+ strExecutive); //decode the placeholder image // placeholder = BitmapFactory.decodeFile("/sdcard/"+strExecutive+"/"+styleCode+"/"); picView.setImageBitmap(placeholder); // placeholder = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); //set placeholder as all thumbnail images in the gallery initially for(int i=0; i<imageBitmaps.length; i++) imageBitmaps[i]=placeholder; //get the styling attributes - use default Andorid system resources TypedArray styleAttrs = galleryContext.obtainStyledAttributes(R.styleable.PicGallery); //get the background resource defaultItemBackground = styleAttrs.getResourceId( R.styleable.PicGallery_android_galleryItemBackground, 0); //recycle attributes styleAttrs.recycle(); }

+0

сэр, На самом деле я хочу добавить свой личный рисунок из своих компьютерных данных в этот проект. & также появляется ошибка «NAT» во время выполнения. Помогите –

Смежные вопросы