android - How to handle onClick event on imageSpan in editText? -


i working on app in user choose image gallery , added in edittext, want if user click on image in edittext should open in fullscreen, used below code :-

public void addtoedt(bitmap bitmap){     spannablestring ss = new spannablestring("abc");     drawable d = new bitmapdrawable(getresources(), bitmap);     d.setbounds(0, 0, d.getintrinsicwidth(), d.getintrinsicheight());     imagespan span = new imagespan(d, imagespan.align_baseline);     ss.setspan(span, 0, 3, spannable.span_inclusive_exclusive);     edt_note.settransformationmethod(null);     edt_note.gettext().insert(edt_note.getselectionstart(), ss);      final int start = ss.getspanstart(span);     final int end = ss.getspanend(span);      clickablespan click_span = new clickablespan() {         @override         public void onclick(view widget) {                    toast.maketext(getapplicationcontext(),"clicked",toast.length_long).show();         }     };      clickablespan[] click_spans = ss.getspans(start, end,  clickablespan.class);      if(click_spans.length != 0) {         // remove click spans         (clickablespan c_span : click_spans) {             ss.removespan(c_span);         }     }      ss.setspan(click_span, start, end, spanned.span_exclusive_exclusive); } 

tried above code not listening onclick event, now, how can listen click event on image , further task?

clickable span @ same start , end locations of edittext.

sb.setspan(cs, imagestartspan,imageendspan , spannable.span_exclusive_exclusive); 

also

edittext.setmovementmethod(linkmovementmethod.getinstance()); 

i cannot write whole code you. try below sample:-

public void addtoedt(bitmap bitmap){     spannablestring ss = new spannablestring();     drawable d = new bitmapdrawable(getresources(), bitmap);     d.setbounds(0, 0, d.getintrinsicwidth(), d.getintrinsicheight());     ss.append("abc"); // append text here     imagespan span = new imagespan(d, imagespan.align_baseline);     ss.setspan(span, 0, 2, spannable.span_exclusive_exclusive); // start(0) , end (2) create image span on abc text     ss.setspan(new clickablespan() {                 @override                 public void onclick(view widget) {                     ss.delete(0, 2);                     edittext.settext(ss);                 }             },0, 2, spannable.span_exclusive_exclusive); // add clickable span , on click delete span , text     edittext.settext(ss); // show image/clickable span in edittext }   edittext.setmovementmethod(linkmovementmethod.getinstance()); 

Comments

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -