In my app I am try to get the Gallery images into the Edit Text randomly , I need like a chat application we can type any text inside the Edit Text also we need to add Gallery images and emoticons, where ever the user need can select and put into the Edit Text have any idea.
Asked
Active
Viewed 1,362 times
1
-
have you tried anything? – Jun 05 '14 at 06:21
-
I have try this code for this link http://hardiknadiyapara.blogspot.in/2012/09/android-chat-application.html – Pans Jun 05 '14 at 06:31
-
In that code i can take the gallery image but i can not take randomly also i will appear on the right corner – Pans Jun 05 '14 at 06:38
-
1http://stackoverflow.com/questions/7470509/how-to-set-random-images-to-imageviews – Jun 05 '14 at 06:41
-
This link useful for the image view but i have used the edit text alone – Pans Jun 05 '14 at 07:02
3 Answers
1
Please refer to this question : StackOverFlow Question
It uses something like this :
b = (Button) findViewById(R.id.Button01))
b.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// in onCreate or any event where your want the user to
// select a file
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,
"Select Picture"), SELECT_PICTURE);
}
});

Community
- 1
- 1
-
I have try this code too but edit text image will appear in right side corner please guide me – Pans Jun 05 '14 at 07:43
-
This code is not useful for put images into the edit text, kindly send me useful answers. – Pans Jun 05 '14 at 09:17
-
Image to a EditText? That's like writing the synthesis of Benzene in a Mathematics Exam. – Jun 05 '14 at 09:46
1
according to this
you should use Spannable strings and parsing your emoticons!!!
-
i have use this link for images http://hardiknadiyapara.blogspot.in/2012/09/android-chat-application.html – Pans Jun 05 '14 at 06:30
-
In that code i can take the gallery image but i can not take randomly also i will appear on the right corner – Pans Jun 05 '14 at 06:38
1
Try this
int position = Selection.getSelectionStart(AgendaWriterEditText.this.getText());
Spanned e = Html.fromHtml("<img src=\"" + imageResource + "\">", imageGetter, null);
// String s2 = Html.toHtml(e);
// Log.w("Agenda", "Before DB->Image is: " + s2);
AgendaWriterEditText.this.getText().insert(position, e);
Thanks everyone for your reply
I have solved the issue by getting the image from the gallery and insert inside the edit text with the code above and the method to get the drawable is
// setting image
holder.dwEdit.setImageGetter(new Html.ImageGetter() {
@Override
public Drawable getDrawable(String source) {
Drawable drawable = null;
try {
// declaring views
ImageView topicImage = new ImageView(_context);
// setting data
topicImage.setImageURI(Uri.parse(source));
// getting Drawable from image to use in HTML <img tag
drawable = topicImage.getDrawable();
Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
ByteArrayOutputStream out = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
drawable = new BitmapDrawable(_context.getResources(),
bitmap);
// Important
if (drawable != null) {
// setting the bounds (width + height)
drawable.setBounds(0, 0, 200, 200);
}
} catch (Exception e) {
Log.e("Hammad", "Failed to load inline image!");
}
return drawable;
}
});
Important
this method is called when edit text read the tag and it give src="path" to this method and that code will return Drawable
Finally image can be added to edit text field

michoprogrammer
- 1,159
- 2
- 18
- 45

Hammad Hasan
- 39
- 3