2012-03-29 8 views
0

これは2つの部分の助けを求める嘆願です。私は画像のギャラリーを作成しています。これは、sdcardの特定のフォルダを取り除くことになります。ギャラリーがスクロールしない

import android.app.Activity; 
import android.os.Bundle; 
import android.widget.AdapterView; 
import android.widget.Gallery; 
import android.widget.ImageView; 
import android.widget.Toast; 

/** 
* @author elidd1 
* 
*/ 
public class GalleryView extends Activity{ 

    ImageView imageView; 
    ; 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.gallery); 

     // Set up an array of the Thumbnail Image ID column we want 
     String[] projection = {MediaStore.Images.Thumbnails._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(MediaStore.Images.Thumbnails._ID); 



    Gallery ga = (Gallery)findViewById(R.id.Gallery01); 
    ga.setAdapter(new GallImageAdapter(this,cursor,columnIndex)); 

     imageView = (ImageView)findViewById(R.id.ImageView01); 


    } 



} 

とカスタムイメージアダプターと呼ばれるGallImageAdapter:

import android.content.Context; 
import android.content.res.TypedArray; 
import android.database.Cursor; 
import android.net.Uri; 
import android.provider.MediaStore; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.BaseAdapter; 
import android.widget.Gallery; 
import android.widget.ImageView; 

public class GallImageAdapter extends BaseAdapter { 
    public Cursor cursor; 
    private int columnIndex; 
    private Context context; 
    int imageBackground; 

    public GallImageAdapter(Context ctx, Cursor cur, int cIn) { 
    context = ctx; 
    columnIndex = cIn; 
    cursor = cur; 
} 

    @Override 
    public int getCount() { 

     return cursor.getCount(); 
    } 

    @Override 
    public Object getItem(int position) { 

     return position; 
    } 

    @Override 
    public long getItemId(int position) { 

     return position; 
    } 

    @Override 
    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); 
      int imageID = cursor.getInt(columnIndex); 

      picturesView.setImageURI(Uri.withAppendedPath(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,""+imageID)); 

      picturesView.setScaleType(ImageView.ScaleType.FIT_CENTER); 
      picturesView.setPadding(10,10,10,10); 

     }else{ 
      picturesView = (ImageView)convertView; 
     } 
     return picturesView; 
    } 

} 

第一の問題は、同様にgetCountメソッドがnullポインタ例外を返しているということです。私はGalleryViewクラスを作成している それがために私を許可していません画像をスクロールします。

私の質問の2番目の部分は、どのように特定のフォルダを指していますか "/ LC/images /"私はこの行の画像アダプタで発生すると仮定しています:

picturesView.setImageURI(Uri.withAppendedPath(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,""+imageID)); 

あなたはそれを使用する前に、カーソルを初期化しない

答えて

1

、あなたがCursorAdapterを使用するか、コンストラクタ

+0

イムでそれを渡すことができます任意の助けのおかげで申し訳ありませんが、私は私の中でそれを起動するのを忘れたことに気づきましたギャラリーのビューと私はそれを投稿するとすぐにアダプタに渡す..私は上記の投稿を編集..まだアダプタに特定のフォルダを渡す方法を知りたい.. – erik

+0

Uri.parse( 'file:/ /あなたの道 ') –

関連する問題