如何在Android中将多个图像从图库设置为imageViews?

时间:2019-04-20 22:10:11

标签: android bitmap imageview

我可以从图库中选择多个图像,但是当我尝试设置它们时,这些图像在我的Imageviews中没有正确排序。我希望将第一个选定的图像放置在第一个ImageView中,依此类推。如何对这些图像进行排序?

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    try {


                if (data.getClipData() != null) {
                    ClipData mClipData = data.getClipData();
                    ArrayList<Uri> mArrayUri = new ArrayList<Uri>();

                    for (int i = 0; i < mClipData.getItemCount(); i++) {

                        ClipData.Item item = mClipData.getItemAt(i);
                        Uri uri = item.getUri();
                        mArrayUri.add(uri);


                        // Get the cursor
                        Cursor cursor = getContentResolver().query(uri, filePathColumn, null, null, null);
                        // Move to first row
                        cursor.moveToFirst();

                        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                        imageEncoded  = cursor.getString(columnIndex);
                        imagesEncodedList.add(imageEncoded);
                        cursor.close();
                    }

                    bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(),mArrayUri.get(0));
                    imageview.setImageBitmap(bitmap);
                    imageview.setVisibility(View.VISIBLE);

                    if(mArrayUri.get(1) != null) {

                        bitmap2 = MediaStore.Images.Media.getBitmap(getContentResolver(), mArrayUri.get(1));
                        imageview2.setImageBitmap(bitmap2);
                        imageview2.setVisibility(View.VISIBLE);
                    }

                    if(mArrayUri.get(2) !=null ){
                        bitmap3 = MediaStore.Images.Media.getBitmap(getContentResolver(), mArrayUri.get(2));
                        imageview3.setImageBitmap(bitmap3);
                        imageview3.setVisibility(View.VISIBLE);
                    }

0 个答案:

没有答案