title: How to show line number in EditText
body: <p>Here I am trying to build an edit text in which shows the line number whenever new line encounters. I made my own Custom edit text as described in this <a href="https://gist.github.com/lifeparticle/de9224424d14a9d6e185" rel="nofollow noreferrer">Using this Link.</a> 
  Here's my code</p>
  
  <pre><code>public class MyEditText extends android.support.v7.widget.AppCompatEditText {
  
      private Rect rect;
      private Paint paint;
  
      public MyEditText(Context context) {
          super(context);
          rect = new Rect();
          paint = new Paint();
          paint.setStyle(Paint.Style.FILL);
          paint.setColor(Color.BLACK);
          paint.setTextSize(20);
      }
  
      @Override
      protected void onDraw(Canvas canvas) {
          int baseline = getBaseline();
          for (int i = 0; i &lt; getLineCount(); i++) {
              canvas.drawText("" + (i+1), rect.left, baseline, paint);
              baseline += getLineHeight();
          }
          super.onDraw(canvas);
      }
  }
  </code></pre>
  
  <p>Here's XML layout of MainActvity </p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"&gt;
      &lt;ScrollView
          android:id="@+id/SCROLLER_ID"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:scrollbars="vertical"
          android:fillViewport="true"&gt;
  
          &lt;android.support.v7.widget.AppCompatEditText
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:text="Type here"
              android:inputType="textMultiLine"
              android:paddingLeft="16dp"
              android:paddingRight="16dp"
              android:paddingTop="16dp"
              android:paddingBottom="16dp"
              android:id="@+id/editor_area"
              android:backgroundTint="@android:color/transparent"
              /&gt;
      &lt;/ScrollView&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>And Here's the Main Activity Code</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  Button button;
      TextView textView;
      MyEditText myEditText;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          myEditText = (MyEditText) findViewById(R.id.editor_area);
  
               // Now what should be further steps to achieve the task
      }
  }
  </code></pre>
  
  <p>I am not able to figure out what's should I do next in this to do this line number thing. I saw many answers on stackoverflow but didn't solve the query, I am new to android. Please help.</p>
  
  <p>Thanks</p>
  
  <p><strong>EDIT</strong> : After doing the alterations based on the following answers this is what i am getting in logcat Window</p>
  
  <pre><code> java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.aman.demo/com.example.aman.demo.MainActivity}: android.view.InflateException: Binary XML file line #14: Binary XML file line #14: Error inflating class com.example.aman.demo.MyEditText
                                                         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
                                                         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                                                         at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                                                         at android.os.Handler.dispatchMessage(Handler.java:105)
                                                         at android.os.Looper.loop(Looper.java:164)
                                                         at android.app.ActivityThread.main(ActivityThread.java:6541)
                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                         at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
                                                      Caused by: android.view.InflateException: Binary XML file line #14: Binary XML file line #14: Error inflating class com.example.aman.demo.MyEditText
                                                      Caused by: android.view.InflateException: Binary XML file line #14: Error inflating class com.example.aman.demo.MyEditText
                                                      Caused by: java.lang.NoSuchMethodException: &lt;init&gt; [class android.content.Context, interface android.util.AttributeSet]
                                                         at java.lang.Class.getConstructor0(Class.java:2320)
                                                         at java.lang.Class.getConstructor(Class.java:1725)
                                                         at android.view.LayoutInflater.createView(LayoutInflater.java:615)
                                                         at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
                                                         at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
                                                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
                                                         at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
                                                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
                                                         at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
                                                         at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292)
                                                         at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                                                         at com.example.aman.demo.MainActivity.onCreate(MainActivity.java:18)
                                                         at android.app.Activity.performCreate(Activity.java:6975)
                                                         at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
                                                         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
                                                         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                                                         at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                                                         at android.os.Handler.dispatchMessage(Handler.java:105)
                                                         at android.os.Looper.loop(Looper.java:164)
                                                         at android.app.ActivityThread.main(ActivityThread.java:6541)
                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                         at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
  </code></pre>