Extending a EditText in Android. What am I doing wrong?

后端 未结 3 1600
无人及你
无人及你 2021-01-04 06:43

So I\'m trying to get a grasp of using custom controls in Android. But my app crashes on trying to create the activity. Here\'s the code:

package com.myApp;
         


        
3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-04 07:32

    You have to add this constructor for creating any custom View.

    public MyEditText(Context context, AttributeSet attrs) {
            super(context, attrs);
    .....
    }
    

    instead of

    public MyEditText(Context context) {
            super(context);
            // TODO Auto-generated constructor stub
        }  
    

提交回复
热议问题