Using custom classes


Staff member
Licensed User
In many cases you will need to extend (subclass) an existing view.
The NativeClass property allows you to override the default type with a custom one. This property doesn't have any effect during design. Only when the layout is loaded.

For example if we want to create a specialized EditText that shows a toast message when the selection area is changed we can create the following class:
   public static class MyEditText extends EditText {
       public MyEditText(Context context) {
      protected void onSelectionChanged(int selStart, int selEnd) {
         if (selEnd - selStart > 0)
            Toast.makeText(getContext(), getText().subSequence(selStart, selEnd), Toast.LENGTH_SHORT).show();
Assuming that this class is declared inside an activity named Test1Activity we should set the NativeClass property to:

Note that if the property starts with a dot then the application package is automatically added.

The layout builder expects a constructor with a single argument which is the context.

- Label is based on TextView. You can use label with any class that extends TextView.
- Panel (without any children) supports all classes that extend View.


Well-Known Member
Licensed User
This is for Designer4Android. It is a separate product to Basic4Android