2012-01-24 11 views
0

sd card.iの特定のフォルダから画像をSDカードのフォルダに保存しようとしています。今、私はそのフォルダから画像をロードしたい。オンラインチュートリアルを使ってこれを行う。しかし、私は下のコードを使用しようとすると何も動作しませんでした。私は空白の画面を受け取りました。 私は何が間違っていますか?助けてくれてありがとうございました。sdカードフォルダから画像をロード

public class F6Activity extends softActivity 
{ 
private Cursor cursor; 
private int columnIndex; 
Button next; 


protected void onCreate(Bundle savedInstanceState) 
{ 
super.onCreate(savedInstanceState); 
setContentView(R.layout.activity_f6); 


Gallery g = (Gallery) findViewById(R.id.gallery); 
//request only the image ID to be returned 
String[] projection = {MediaStore.Images.Media._ID}; 
//Create the cursor pointing to the SDCard 
cursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, 
    projection, 
    MediaStore.Images.Media.DATA + " like ? ", 
    new String[] {"%ereports%"}, 
    null); 
    //Get the column index of the image ID 
    columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID); 
    g.setAdapter(new ImageAdapter(this)); 



    } 


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; 
} 

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 
ImageView i = new ImageView(context); 
// Move cursor to current position 
cursor.moveToPosition(position); 
// Get the current value for the requested column 
int imageID = cursor.getInt(columnIndex); 
// obtain the image URI 
Uri uri = Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,  
Integer.toString(imageID)); 
String url = uri.toString(); 
// Set the content of the image based on the image URI 
int originalImageId = Integer.parseInt(url.substring(url.lastIndexOf("/") + 1, 
url.length())); 
Bitmap b = MediaStore.Images.Thumbnails.getThumbnail(getContentResolver(), 
       originalImageId, MediaStore.Images.Thumbnails.MINI_KIND, null); 
i.setImageBitmap(b); 
i.setLayoutParams(new Gallery.LayoutParams(150, 100)); 
i.setScaleType(ImageView.ScaleType.FIT_XY); 
int mGalleryItemBackground = 0; 
i.setBackgroundResource(mGalleryItemBackground); 

return i; 
} 
} 




} 
+0

? –

+0

あなたのreply.iにcode.iを編集していただきありがとうございます。これはsetContentView(R.layout.activity_f6);である必要があります。それでも私は空白の画面を受け取った。 – TRS

+0

この質問は100回以上尋ねられました。質問を投稿する前に、関連する用語を検索してください。 –

答えて

1

私はコードと混同していますが、今はコード内で問題を言うことができません。それは私にとって時間がかかります。私は下のリンクで利用可能なコードを使用することをお勧めします。それは正常に動作しています。私はその後あなたのコードで問題を見つけることを試みます。今すぐ下のリンクを確認してください。あなたがのonCreate mathodの初めに二回setContentViewメソッドを呼び出している理由

Display images from SD card

+0

OK.Iをチェックしますあなたのリンク。ありがとう.. – TRS

関連する問題