Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

inserting textview inside edittext in android?

I am trying to insert a textview inside a Edittext as in below

enter image description here

can anyone pls give me ideas about how to implement it or something.

thanks :)

update: the textviews in the edittext will vary dynamically.

like image 686
kAnNaN Avatar asked May 19 '12 10:05

kAnNaN


2 Answers

Try this sample code. It fits your requirement.

PopupWindow pw = new PopupWindow(
                                 this.getViewInflate().inflate(R.layout.pw_layout, 
                                                               null, true, null), 
                                100,100,true);
// display the popup in the center
pw.showAtLocation(layout, Gravity.CENTER, 0, 0);
pw.update(20,20,100,100);

For the views inside EditText part, you 'll have to extend the EditText. Overview of how it should look is as follows.

class emailEditText extends EditText {

List<NamePhotoView> ViewlistOfSelectedContacts; // create new

    void addContact(String name, Bitmap photo) {
       // create a new 'NamePhotoView' and add to the ViewlistOfSelectedContacts
    }

    @Override
    void onDraw(Canvas canvas) {
        for (....) {
            // draw all views from the list. left to right.
        }
    // you have to some how offset the text start coordinate. then call super
    super.onDraw(canvas);
    }
}
like image 149
Ronnie Avatar answered Oct 27 '22 23:10

Ronnie


I think you cannot set TextView inside EditText. But alternatively you can make it look that way. Here are the steps

  1. convert textview to BitmapDrawable
  2. convert bitmap drawable into SpanableString (ImageSpan)
  3. then set this returned SpannableString to your EditText

I have recently completed this kind of ui and i have explained in my blog Making GoSmsPro/Evernote like EditText

like image 43
Krishna Shrestha Avatar answered Oct 28 '22 00:10

Krishna Shrestha