Custom Editors

2 posts, 0 answers
  1. Vaggelis
    Vaggelis avatar
    4 posts
    Member since:
    Apr 2016

    Posted 22 Apr Link to this post

    Greetings,

    I am trying to create a custom editor for one of my properties. The code I use is this:

     

    [Android.Runtime.Register("my/name/space/ReaderEditor")]
        public class ReaderEditor : Com.Telerik.Widget.Dataform.Visualization.Core.EntityPropertyEditor
        {
            public ReaderEditor(RadDataForm form, IEntityProperty property) : base(form,
                form.EditorsMainLayout,
                form.EditorsHeaderLayout,
                Resource.Id.data_form_text_viewer_header1,
                Resource.Layout.DataFormTextViewerLayout,
                Resource.Id.data_form_text_viewer,
                form.EditorsValidationLayout,
                property)
            {            
            }

            public ReaderEditor(RadDataForm dataForm, int layoutId, int headerLayoutId,
                int headerViewId, int editorLayoutId, int editorViewId,
                int validationLayoutId, IEntityProperty property) :

                base(dataForm, layoutId, headerLayoutId, headerViewId, editorLayoutId,
                    editorViewId, validationLayoutId, property)
            {
            }

            public override Java.Lang.Object Value()
            {
                return ((EditText)EditorView).Text;
            }

            protected override void ApplyEntityValueToEditor(Java.Lang.Object entityValue)
            {
                ((EditText)EditorView).Text = entityValue.ToString();
            }
        }

     

    It's pretty basic actually, I just wanted to create a simple one in order to build on that afterwards. However when I run it I get the following exception:

     

    Java.Lang.Error: The data form editor for property MYPROPERTY must have a constructor that accepts a Context and an EntityProperty.

     

    How can I implement this editor?

    Thank you for your time,

    Vaggelis

  2. Todor
    Admin
    Todor avatar
    778 posts

    Posted 27 Apr Link to this post

    Hello Vaggelis,

    From the provided information I can't reproduce an issue. Since you haven't included a full project but simply the custom editor class, I'd like to point out a few details which may be the cause for your issue.

    1) "form.EditorsHeaderLayout" should be a layout for the header and "Resource.Id.data_form_text_viewer_header1" should be an id inside that layout. If you are using defaults, use the following id: "Resource.Id.data_form_text_viewer_header".
    2) Similarly, the next two parameters are the layout for the editor and an id that's inside that layout
    3) When you have your class ready, you can "attach" it to the data form with a custom EditorProvider:

    public class MyEditorProvider : Java.Lang.Object, IFunction {
        private RadDataForm dataForm;
        public MyEditorProvider(RadDataForm dataForm) {
            this.dataForm = dataForm;
        }
     
        public Java.Lang.Object Apply (Java.Lang.Object p0)
        {
            IEntityProperty property = (IEntityProperty)p0;
            if(property.Name().Equals("EmployeeType")) {
                return new ReaderEditor(dataForm, property);
            }
     
            return null;
        }
    }

    And here's how to add it to the data form:

    dataForm.Adapter.SetEditorProvider(new MyEditorProvider(dataForm));

    I hope this information helps. If your issue persist, please provide more exact reproduction steps.

    Regards,
    Todor
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. DevCraft banner
Back to Top