2014-11-26 3 views
0

Как я могу сделать, чтобы все фотографии из моей галереи отображались в одном представлении в Android Studio? Мне нужно, чтобы все мои фотографии использовались после распознавания лиц.Все фотографии из галереи в представлении - Android

Вот Начальный мой код:

package com.face.user.faceapplication; 

import android.app.Activity; 
import android.content.Intent; 
import android.database.Cursor; 
import android.graphics.BitmapFactory; 
import android.net.Uri; 
import android.os.Bundle; 
import android.provider.MediaStore; 
import android.view.View; 
import android.widget.Button; 
import android.widget.ImageView; 

//import static android.widget.ImageView.*; 


public class FirstClass extends Activity { 
    private static int RESULT_LOAD_IMAGE = 1; 
    // private ImageView image; 


    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_my_activity); 
     Button button = (Button) findViewById(R.id.button); 

     // ImageView image = (ImageView) findViewById(R.id.image); 
     button.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View arg0) { 
       Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 
       startActivityForResult(i, RESULT_LOAD_IMAGE); 
      } 
     }); 
    } 

    private static int LOAD_IMAGE_RESULTS = 1; 

    @Override 
    //semmi 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     super.onActivityResult(requestCode, resultCode, data); 
     if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) { 
      Uri selectedImage = data.getData(); 
      String[] filePathColumn = {MediaStore.Images.Media.DATA}; 
      Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null); 
      cursor.moveToFirst(); 
      int columnIndex = cursor.getColumnIndex(filePathColumn[0]); 
      String picturePath = cursor.getString(columnIndex); 
      cursor.close(); 
      ImageView imageView = (ImageView) findViewById(R.id.image); 
      imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath)); 
     } 

    } 
} 

и XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 

    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context=".MyActivity"> 

    <Button 
     android:id="@+id/button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginLeft="15dp" 
     android:layout_marginTop="15dp" 
     android:text="Click here" /> 

    <ImageView 
     android:id="@+id/image" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" 
     android:src="@drawable/ic_launcher" /> 

</RelativeLayout> 

, но если я запускаю это я могу просто выбрать одну фотографию из моей галереи, и мне нужно их все в представлении.

ответ

0

вам нужно использовать putExtra на намерения, как это:

// ImageView image = (ImageView) findViewById(R.id.image); 
     button.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View arg0) { 
       Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 
       i.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); 
       startActivityForResult(i, RESULT_LOAD_IMAGE); 
      } 
     }); 

нотабене Работает в API 18 и выше.

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