いいえiam建物写真ギャラリー(添付ファイル)5枚の写真をアップロードできます。 ので、私はActivityResult を使ってImageViewの中で複数の写真を設定するために、あなたがここにすべてのImageViewの画像ビューで複数の写真を設定します。
からそれをアップロードする必要があり、そうしたいが、私のコードは
ivAttachment1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, RESULT_LOAD_IMAGE);
}
});
ivAttachment2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, RESULT_LOAD_IMAGE);
}
});
ivAttachment3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, RESULT_LOAD_IMAGE);
}
});
ivAttachment4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, RESULT_LOAD_IMAGE);
}
});
ivAttachment5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, RESULT_LOAD_IMAGE);
}
});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == Activity.RESULT_OK && data != null) {
//get picture path
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);
Bitmap bm = BitmapFactory.decodeFile(picturePath);
int width = bm.getWidth();
int height = bm.getHeight();
//convert to base64
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 100, baos); //bm is the bitmap object
byte[] b = baos.toByteArray();
strPhoto1 = Base64.encodeToString(b, Base64.NO_WRAP);
strPhoto2 = Base64.encodeToString(b, Base64.NO_WRAP);
strPhoto3 = Base64.encodeToString(b, Base64.NO_WRAP);
strPhoto4 = Base64.encodeToString(b, Base64.NO_WRAP);
strPhoto5 = Base64.encodeToString(b, Base64.NO_WRAP);
//show the image
ivAttachment1.setImageBitmap(bm);
ivAttachment2.setImageBitmap(bm);
ivAttachment3.setImageBitmap(bm);
ivAttachment4.setImageBitmap(bm);
ivAttachment5.setImageBitmap(bm);
}
}
であり、ここで私のレイアウトコードは
<RelativeLayout
android:layout_width="match_parent"
android:id="@+id/rlAttachment"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="200dp"
android:layout_marginLeft="15px"
android:id="@+id/ivAttachment1"
android:src="@drawable/profpic" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="200dp"
android:layout_margin="15px"
android:src="@drawable/profpic"
android:id="@+id/ivAttachment2"
android:layout_below="@id/ivAttachment1"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="200dp"
android:layout_margin="15px"
android:id="@+id/ivAttachment3"
android:layout_below="@id/ivAttachment2"
android:src="@drawable/profpic" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="200dp"
android:layout_margin="15px"
android:layout_below="@id/ivAttachment3"
android:id="@+id/ivAttachment4"
android:src="@drawable/profpic" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="200dp"
android:layout_below="@id/ivAttachment4"
android:id="@+id/ivAttachment5"
android:layout_margin="15px"
android:src="@drawable/profpic" />
</RelativeLayout>
です
しかし、問題は、私がivAttachment1にアップロードしたときに、他のものがivAttachment2,3,4と5の同じ画像にアップロードされることです。おそらく、何らかの「スイッチ」メソッドを作成する必要があります。私はデータベースに保存することができるように、すべてのビットマップ写真を文字列に配置する必要があります。 あなたは私に最も控えめな方法を見せることができますか?
あなたはImageViewのをクリックして、クリックされたImageViewのためのonActivityResultチェックして、その後、さらなる行動を行うされて維持する必要がありますあなたの