2012-09-27 3 views
0

ArrayList의 MediaStore.Images.Media.DATA 문자열을 배열로 읽어서 배열 대신 SD 카드의 이미지를 사용할 수 있습니다. coverflow 갤러리 응용 프로그램을위한 R.drawable 폴더의 이미지. 벽돌 벽에 부딪쳤다. 이미지 정보를위한 정수형 대 문자열 형을 읽는 문제.URI의 ArrayList <String>을 R.drawable 대신 coverflow 앱에 넣습니다.

은 SD 카드의 모든 이미지에서 arraylist로 URI를 가져올 수 있었고 취할 다음 단계는 무엇인지 알 수 없었습니다.

이 접근법을 계속 사용하는 것이 좋으며,이 방법을 포기하고이 커버 플로우 응용 프로그램의 이미지 소스를 R.drawables 폴더에서 SD 카드로 변경하는 작업을 수행하는 다른 방법을 시도해 보는 것이 좋습니다. 여기

내가 무슨 짓을

첫째, 여기 프로세스의 일환으로 배열을 사용하여 안드로이드에 R.drawable 폴더에서 이미지를 얻는 방법입니다

 public class ImageAdapter extends BaseAdapter { 
     int mGalleryItemBackground; 
     private Context mContext; 

     private FileInputStream fis; 

     // private Integer[] mImageIds = { 
     //  R.drawable.pic01, 
     //  R.drawable.pic02, 
      // R.drawable.pic03, 
      // R.drawable.pic04, 
      // R.drawable.pic05, 
      // R.drawable.pic06, 
      // R.drawable.pic07, 
     //  R.drawable.pic08, 
     // R.drawable.pic09 
     // }; 

     private ImageView[] mImages; 

내 생각이었다가 커서를 사용하여 SD 카드에서이 "//mnt/sdcard/pic01.png"와 같은 URI를 읽고 "R.drawable.pic02"와 같은 R.drawables의 배열에있는 주소 대신이 주소를 사용합니다. 배열에.

이것은 내가 한 것이며이 부분은 문제없이 작동했습니다. SD 카드의 이미지에서 모든 URI를 가져 와서 arrayList에 저장했습니다. 지금까지 모든 것이 잘 작동합니다. Toast를 사용하여로드 된 URI를 활동 화면에 표시하여 완벽하게 작동하는지 확인했습니다.

 ArrayList<String> list1 = new ArrayList<String>(); 

    String[] proj = {MediaStore.Images.Media.DATA}; 
    Cursor cur = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, proj, null, null, null); 
    if (cur.getCount() > 0) { 
     while (cur.moveToNext()) { 
      String pic = cur.getString(cur.getColumnIndex(MediaStore.Images.Media.DATA)); 
      list1.add(pic); 
     // Toast.makeText(CoverFlowExample.this, "data name: " + pic, Toast.LENGTH_SHORT).show(); 
     // Log.d("TAG", "ID: " + pic); 
     } 
     } 
    cur.close(); 

다음 나는 R.drawables 배열에 사용되는 배열에이 문자열을 읽기를 시도하고 내가 문제에있어 곳이다 : 프로그램은 배열의 형태로서 정수를 사용합니다. 그래서이 배열은 URI를 읽는 잘못된 장소라고 생각합니다. 그때 이것이 틀린 장소 인 경우에. 지금 무엇을해야할까요? 여기
 mImageIds[t]= list1.get(t); 

이 응용 프로그램의의 getView 부분에서 코드의 나머지 부분입니다 :

  Integer[] mImageIds = new Integer[list1.size()]; 

    for(int t = 0; t<= list1.size(); t++){ 
     mImageIds[t]= list1.get(t); // type mismatch cannot convert string to integer 
    } 

    Toast.makeText(CoverFlowExample.this, "data name: " + y , Toast.LENGTH_SHORT).show(); 

내가 점점 오전 오류가이 부분에 대해 "형식이 일치하지가 정수에 문자열을 변환 할 수 없습니다"입니다 난 지금 다음에 무엇을해야할지 알아 내려고 노력 중입니다. 이미 URI를/파일 시스템 경로를 따라

  public View getView(int position, View convertView, ViewGroup parent) { 

     //Use this code if you want to load from resources from external source 
     ImageView i = new ImageView(mContext); 

      // this method is what someone suggested to use but i don't know how to use this, what do i put for "image" and how to read URIs from arrayList to this? 
     i.setImageBitmap(BitmapFactory.decodeFile("image_" + position)); 

      // this works for reading in only one image from the SD card into the coverflow app 
     i.setImageBitmap(BitmapFactory.decodeFile("/mnt/sdcard/pic04.png")); 

    // when getting from R.drawable images --> i.setImageResource(mImageIds[position]); 

     i.setLayoutParams(new CoverFlow.LayoutParams(130, 130)); 
     i.setScaleType(ImageView.ScaleType.MATRIX);   
     return i; 

     //return mImages[position]; 
    } 

답변

0

, 당신은로드 가지고 Drawablejava doc in android docucreateFrom* 방법 중 하나를 사용할 수 있습니다.