Home How to create dynamic image and edit text
Reply: 0

How to create dynamic image and edit text

user2539
1#
user2539 Published in April 23, 2018, 9:37 am

I am selecting multiple images, but viewing one editText; I want to select multiple images and get multiple editText's around.

Simply put

I am trying to dynamically add the image pic from a gallery and at the same time I want to have editText's in the same amount as of selected images count from the gallery.

My code is below. How can I fix this problem?

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);
}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.438166 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO