-1

My code is

 namespace classlibrary
 {
   public class numerictext : EditText
    {
      //My code

    } 

When I try to inherit a edit text control in a class library, I'm getting the error: Parent does not contain a constructor that takes 0 arguments. I understand the problem is that Parent has no constructor with 0 arguments. But how to inherit a control in a class library?

Raj
  • 40
  • 4

3 Answers3

2

For any Android-based View subclass, you need to supply the three constructors that call their base object constructors, ie.:

public class MyView : EditText
{
    public MyView(Context context) : base(context) { }
    public MyView(Context context, IAttributeSet attrs) : base(context, attrs) { }
    public MyView(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle) { }

    // your override code....
}
SushiHangover
  • 73,120
  • 10
  • 106
  • 165
1

You need to call one of the base constructors in your derived class. Assuming you are using the Android EditText widget:

public class numerictext : EditText
{
    public numerictext(Context context) : base(context)
                                      //^^^^^^^^^^^^^^^ 
                                      //Note how we are now calling the base constructure
    {
        //empty or you can add your own code
    }

    public numerictext(Context context, IAttributeSet attrs) : base(context, attrs)
    {
    }

    //etc
} 
DavidG
  • 113,891
  • 12
  • 217
  • 223
-3

Have you considered changing EditText to:

public class EditTtext 
{
   data stuff..
   EditText() {}

   other functions
}

Though I don't see why yours wouldn't work as is

Yogi Bear
  • 943
  • 2
  • 16
  • 32
  • I want to create numeric text box in android.I need to create the control in class library by inheriting edit text. When i try to inherit , i'm getting the error. – Raj Jul 08 '18 at 16:32
  • The EditText class he's using is a Xamarin Forms control. He needs to subclass a control, and for that call the correct base constructors. – Curtis Shipley Jul 08 '18 at 23:19