我正在选择多个图片,但是查看一个editText;我想选择多个图像并获得多个editText。
我正在尝试从图库中动态添加图片图片,同时我希望editText与图库中所选图片的数量相同。
我的代码如下。我该如何解决这个问题?
private void onSelectFromGalleryResult(List<String> data) {
Bitmap bm = null;
int position = 0;
int width = 1;
int height = 1;
editArray = new EditText[data.size()];
imageArray = new ImageView[data.size()];
for (int i = 0; i < data.size(); i++) {
editArray[i] = new EditText(ActionStatusActivity.this);
imageArray[i] = new ImageView(ActionStatusActivity.this);
editArray[i].setId(i);
imageArray[i].setId(i);
if (i != 0) {
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
200,
200);
params.setMarginStart(100);
params.addRule(RelativeLayout.BELOW, imageArray[i - 1].getId());
mTextParams.addRule(RelativeLayout.RIGHT_OF, imageArray[i].getId());
imageArray[i].setLayoutParams(params);
editArray[i].setLayoutParams(mTextParams);
mLayoutImage.addView(imageArray[i], params);
mLayoutImage.addView(editArray[i]);
}
else {
mTextParams.addRule(RelativeLayout.RIGHT_OF, imageArray[i].getId());
editArray[i].setLayoutParams(mTextParams);
mLayoutImage.addView(imageArray[i]);
mLayoutImage.addView(editArray[i]);
}
try {
bm = MediaStore.Images.Media.getBitmap(
getApplicationContext().getContentResolver(),
Uri.fromFile(new File(data.get(i))));
}
catch (IOException e) {
e.printStackTrace();
}
imageBase64 = encodeTobase64(bm);
imageArrayString.add(imageBase64);
String path = MediaStore.Images.Media.insertImage(
this.getContentResolver(), bm, "", null);
Glide.with(getApplicationContext()).load(path).asBitmap().override(200, 200).centerCrop().into(imageArray[i]);
}
mLayoutParams = new RelativeLayout.LayoutParams(
mLayoutImage.getWidth(), 200 * data.size());
mLayoutImage.setLayoutParams(mLayoutParams);
}