Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
203 views
Welcome To Ask or Share your Answers For Others

1 Answer

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....
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...