0

In my app I am going to appear one screen,In that screen I am going to put the edit text field and below that edit text field I will use pick and save buttons,inside the edit text field I am going to type some text and after that where the cursor is pointing in that place I have to add the images, I would like to be taken images from the gallery using pick button and after put the images into the edit text field again I want to type some thing after that I am going to click the save button that edit text field saved as a images into the gallery are some thing else I have searched in Google regarding this but I can not able to find any solutions please any one would help me.

The below image i want to save as image view and i need to add the image into the edit text field again where the cursor pointing in the place i have to pick the image from gallery

Manoj
  • 3,947
  • 9
  • 46
  • 84
  • That is known as chips or bubble kind edit text. You can get some idea from http://stackoverflow.com/questions/10812316/contact-bubble-edittext or http://www.kpbird.com/2013/02/android-chips-edittext-token-edittext.html, and if your app's minimumsdk level is 14 then try https://plus.google.com/+RomanNurik/posts/WUd7GrfZfiZ – Hardik Trivedi May 23 '14 at 13:55
  • I have used the layout for the edit text field i need the java code to pick and save the images files. – Manoj May 23 '14 at 14:35
  • where do you want the image save to? – penkzhou May 23 '14 at 16:51
  • I want to save the whole edit text field as Image into the gallery or SD card,Before that how do i pick the images into the edit text field as i given link [1]: http://i.stack.imgur.com/USlnQ.png – Manoj May 24 '14 at 04:28
  • Updated reply in answer. Let me know if u still face problem. – Hardik Trivedi May 26 '14 at 04:56
  • You gave one link know, It is running but it showing only the edit text fields alone how can i get the images into the edit text. – Manoj May 26 '14 at 06:30

1 Answers1

1

EditText is a one type of View. Convert that view into bitmap and store them where ever you want. And Java code for that is

// capture bitmapt of genreated textview
int spec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
textView.measure(spec, spec);
textView.layout(0, 0, textView.getMeasuredWidth(), textView.getMeasuredHeight());
Bitmap b = Bitmap.createBitmap(textView.getWidth(), textView.getHeight(),Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(b);
canvas.translate(-textView.getScrollX(), -textView.getScrollY());
textView.draw(canvas);
textView.setDrawingCacheEnabled(true);
Bitmap cacheBmp = textView.getDrawingCache();
Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888, true);
textView.destroyDrawingCache(); // destory drawable

Find full example in this class https://github.com/kpbird/chips-edittext-library/blob/master/ChipsEditTextLibrary/src/com/kpbird/chipsedittextlibrary/ChipsMultiAutoCompleteTextview.java

Set image in EditText

SpannableStringBuilder ssb = new SpannableStringBuilder("");
    BitmapDrawable bmpDrawable = new BitmapDrawable(viewBmp);
    bmpDrawable.setBounds(0, 0,bmpDrawable.getIntrinsicWidth(),bmpDrawable.getIntrinsicHeight());
    // create and set imagespan
    ssb.setSpan(new ImageSpan(bmpDrawable),x ,x + c.length() , Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
edtText.setText(ssb);
Hardik Trivedi
  • 5,677
  • 5
  • 31
  • 51
  • Before that i need to take the image from the gallery to the edit text if there is any possible. – Manoj May 26 '14 at 05:21
  • Updated my answer. Also please have a look at the link. Code for both(Image to text and text to image) is available there. – Hardik Trivedi May 26 '14 at 05:31
  • sorry Hardik Trivedi, this code is not help full for me, I want to pick the images from the gallery. – Manoj May 26 '14 at 07:06
  • To pick image from gallery use intents http://stackoverflow.com/questions/2507898/how-to-pick-an-image-from-gallery-sd-card-for-my-app-in-android – Hardik Trivedi May 26 '14 at 07:14
  • inside the edit text field how can i get the images from the gallery, weather i want to use image view inside the image view. – Manoj May 26 '14 at 09:55
  • http://i.stack.imgur.com/USlnQ.png You can see this link I will take the images like this only to edit text from the gallery, I got sample code for this but they pick the image from the drawable, but I want to pick from gallery would you help me pls. – Manoj May 26 '14 at 09:59
  • Buddy I am trying to explain you the same thing. Did u give a try to above code. there one image is appeded after text, you need to modify above logic for 3 images as you have shown in your reference image. And convert images to bitmap whatever you are getting from gallery. – Hardik Trivedi May 26 '14 at 10:12
  • Buddy no 3 images, first initially we type something in then the cursor is pointing, on that time we click the gallery button and choose one image and add into the edit text fields, then we will type something again we click the gallery again import any image into the edit fields . – Manoj May 26 '14 at 10:48
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/54486/discussion-between-hardik-trivedi-and-manoj). – Hardik Trivedi May 27 '14 at 04:48
  • I got a error on this line for null pointer exception ssb.setSpan(new ImageSpan(bmpDrawable),x ,x + c.length() , Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); – Manoj May 27 '14 at 09:54
  • ssb.setSpan(new ImageSpan(bmpDrawable),x ,x + c.length() , Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); I got an error on this line – Manoj May 27 '14 at 10:28