Live character count in notepad EditText android -


i have custom edittext notepad . in need show live character count can me started.

lineedittext.java

public class linededittext extends edittext {     private rect mrect;     private paint mpaint;     int initialcount=10     @suppresslint("newapi")     public linededittext(context context, attributeset attrs) {         super(context, attrs);      mrect = new rect();     mpaint = new paint();     mpaint.setstyle(paint.style.fill_and_stroke);     mpaint.setcolor(color.parsecolor("#c0c0c0")); //set own color here    /*initialcount=getminlines();     setlines(initialcount);*/ }  @override protected void ondraw(canvas canvas) {     //int count = getlinecount();      int height = getheight();     int line_height = getlineheight();      int count = height / line_height;      if (getlinecount() > count)         count = getlinecount();//for long text scrolling      rect r = mrect;     paint paint = mpaint;     int baseline = getlinebounds(0, r);//first line      (int = 0; < count; i++) {          canvas.drawline(r.left, baseline + 1, r.right, baseline + 1, paint);         baseline += getlineheight();//next line     }      super.ondraw(canvas); } 

}

xml layout

<com.rb.lined.edittext.linededittext                 android:id="@+id/edit_story"                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                                 android:background="@null"                 android:inputtype="textmultiline|textnosuggestions"                 android:minlines="5"                 android:singleline="false"                 android:imeoptions="actionnone"                 android:text=""                  android:textsize="13sp"                 android:gravity="top|left"                 android:layout_below="@+id/txt_story"                 app:typeface="roboto_condensed"                 android:maxlength="180"/> 

you can use textwatcher object on edittext. it's assigned value change listener.

android developer - textview @ addtextchangedlistener

android developer - textwatcher


Comments

  1. This is a good post. This post gives truly quality information. I’m definitely going to look into it. Really very useful tips are provided here. Thank you so much. Keep up the good works. this

    ReplyDelete

Post a Comment

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -