-1

I am developing an android application, where I have an EditText in which I want users to put message along with the image in the same EditText.how can a user be able to put images in EditText view please help.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Digvijay
  • 2,887
  • 3
  • 36
  • 86

2 Answers2

0

Use ImageSpan

Just like SpannableStrings, you can also use ImageSpan to add to your EditText.

Spannable span = new SpannableString("Some text that you want to add");
Drawable android = context.getResources().getDrawable(R.drawable.sampeImage);
android.setBounds(0, 0, 32,32);
ImageSpan image = new ImageSpan(android, ImageSpan.ALIGN_BASELINE);
span.setSpan(image, 3, 4, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
editTextView.setText(span);

Just like above you can have any drawable and add this to span. and then set this span to edit textview

Avtar Guleria
  • 2,126
  • 3
  • 21
  • 33
  • How can i get text and image from the users and not from the drawable folder. – Digvijay Jan 30 '18 at 07:43
  • You can open gallery and allow user to select image from that. Refer this link for the same. https://stackoverflow.com/questions/38352148/get-image-from-the-gallery-and-show-in-imageview – Avtar Guleria Jan 30 '18 at 08:15
  • Now i got image from gallery intent but how can i set this to spannable string. – Digvijay Jan 30 '18 at 09:02
  • Convert bitmap to drawable and use it in above code. Drawable drawable = new BitmapDrawable(context.getResources(), bitmap); – Avtar Guleria Jan 30 '18 at 10:00
0

First thing first: Use Spannable String:

Here -> Stack answer to Follow Along

This one is also similar -> Another Stack answer

--- if you want the images to be uploaded by user instead of drawable then you have multiple ways to allow the user upload images.. please follow along these links

Example # 01

Nice tutorial here

Basic but useful

if you stuck with any specific problem.. please come up with your code highlighting the area where you're stuck at..

Salman Anjum
  • 333
  • 3
  • 7