1

BUCKET_LIST_NAME を使用してすべてのフォルダーとフォルダーの名前を表示するクラス アダプターがあります。ただし、フォルダは同じ名前 = 写真です。別の名前を取得する方法、つまり、各フォルダーの実際の名前を取得する方法を意味しますか??? ありがとう。

public class ThumbnailAdapter extends BaseAdapter {

// Context required for performing queries
private final Context mContext;

// Cursor for thumbnails
private final Cursor cursor;

private final int count;

String bucket;
String id;


public ThumbnailAdapter(Context c) {
    this.mContext = c;

    // Get list of all images, sorted by last taken first
    final String[] projection = {
            MediaStore.Images.Media.BUCKET_ID,
            MediaStore.Images.Media.BUCKET_DISPLAY_NAME
    };
    String BUCKET_GROUP_BY =
            "1) GROUP BY 1,(2";
    String BUCKET_ORDER_BY = "MAX(datetaken) DESC";

    cursor = mContext.getContentResolver().query(
            MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            projection,
            BUCKET_GROUP_BY,
            null,
            BUCKET_ORDER_BY
    );
    if (cursor.moveToFirst()) {

        int bucketColumn = cursor.getColumnIndex(
                MediaStore.Images.Media.BUCKET_DISPLAY_NAME);

        int idColumn = cursor.getColumnIndex(
                MediaStore.Images.Media.BUCKET_ID);


        do {
            // Get the field values
            bucket = cursor.getString(bucketColumn);
            id = cursor.getString(idColumn);


        } while (cursor.moveToNext());
    }

    count = cursor.getCount();
    Log.d("ThumbnailAdapter", count + " images found");
}

@Override
public int getCount() {
    return count;
}

@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) {

      LinearLayout ll = new LinearLayout(mContext);

      ImageView imageView = new ImageView(mContext);
      TextView mytext = new TextView(mContext);
     mytext.setText(bucket);
      imageView.setImageResource(R.drawable.your_folder_icon);
      ll.addView(imageView);
      ll.addView(mytext);



    return ll;
}
4

1 に答える 1

1

カーソルを初期化します。

final String[] projection = {
            MediaStore.Images.Media.BUCKET_ID,
            MediaStore.Images.Media.BUCKET_DISPLAY_NAME
    };
    String BUCKET_GROUP_BY =
            "1) GROUP BY 1,(2";
    String BUCKET_ORDER_BY = "MAX(datetaken) DESC";

    cursor = mContext.getContentResolver().query(
            MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            projection,
            BUCKET_GROUP_BY,
            null,
            BUCKET_ORDER_BY
    );

次を使用してアダプターに渡します。

CursorAdapter adapter = ThumbnailAdapter(mContext, cursor);

あなたのアダプタークラス:

public class ThumbnailAdapter extends CursorAdapter 
{
    LayoutInflater mInflater;
    Context context;
    Cursor cursor;
    String bucket;
    String id;

    public ThumbnailAdapter(Context context, Cursor c) 
    {
        super(context, c);
        this.context = context;
        this.cursor = c;
        mInflater = LayoutInflater.from(context);
    }
    @Override
    public void bindView(View view, Context context, Cursor cursor) 
    {
        TextView mytext = (TextView) view.findViewById(R.id.mytext);
        ImageView imageView = (ImageView) view.findViewById(R.id.imageView);

         mytext.setText(bucket);
        imageView.setImageResource(R.drawable.your_folder_icon);
    }
    @Override
    public View newView(Context arg0, Cursor arg1, ViewGroup arg2)
    {
        View v = mInflater.inflate(R.layout.checklistitem_withbutton, null); // Your XML View.
        return v;
    }
}
于 2014-06-09T06:53:15.537 に答える