Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

EntryRenderer TextChanged

$
0
0

Hi everyone,

I'm making an XF Android application, and i need the user to auto login when he types a code (after 4 digits).

I've done a 'ExtendedEntry' class with a EntryRenderer to limits the maxLength of the entry. (And customize the UI later).

Then i attached to my ExtendedEntry TextChanged event a TextChangedHandler function which is in my XamlPage CodeBehind and test if the text has 4 greater or equal than 4 digits. It works fine excepted when it does have 4 digits, and i navigateTo the next page i got this exception:

System.NotSupportedException: Unable to activate instance of type Ftel.MobileApp.Droid.Infrastructure.Renderers.ExtendedEntryRenderer_Android from native handle 0xbe9e4b8c (key_handle 0x84dd90a). ---> System.MissingMethodException: No constructor found for Ftel.MobileApp.Droid.Infrastructure.Renderers.ExtendedEntryRenderer_Android::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.
  at Java.Lang.Error: Exception of type 'Java.Lang.Error' was thrown.
  at --- End of managed exception stack trace ---
  at java.lang.Error: Java callstack:
  at at md5b60ffeb829f638581ab2bb9b1a7f4f3f.EntryRenderer.n_afterTextChanged(Native Method)
  at at md5b60ffeb829f638581ab2bb9b1a7f4f3f.EntryRenderer.afterTextChanged(EntryRenderer.java:50)
  at at android.widget.TextView.sendAfterTextChanged(TextView.java:9021)
  at at android.widget.TextView$ChangeWatcher.afterTextChanged(TextView.java:11660)
  at at android.text.SpannableStringBuilder.sendAfterTextChanged(SpannableStringBuilder.java:976)
  at at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:520)
  at at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:456)
  at at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:33)
  at at android.view.inputmethod.BaseInputConnection.replaceText(BaseInputConnection.java:691)
  at at android.view.inputmethod.BaseInputConnection.commitText(BaseInputConnection.java:199)
  at at com.android.internal.widget.EditableInputConnection.commitText(EditableInputConnection.java:184)
  at at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:286)
  at at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:78)
  at at android.os.Handler.dispatchMessage(Handler.java:102)
  at at android.os.Looper.loop(Looper.java:145)
  at at android.app.ActivityThread.main(ActivityThread.java:6862)
  at at java.lang.reflect.Method.invoke(Native Method)
  at at java.lang.reflect.Method.invoke(Method.java:372)
  at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
  at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
  --- End of inner exception stack trace ---
  at Java.Interop.TypeManager.CreateProxy (System.Type type, IntPtr handle, JniHandleOwnership transfer) [0x00039] in /Users/builder/data/lanes/2512/d3008455/source/monodroid/src/Mono.Android/src/Java.Interop/TypeManager.cs:299
  at Java.Interop.TypeManager.CreateInstance (IntPtr handle, JniHandleOwnership transfer, System.Type targetType) [0x0012c] in /Users/builder/data/lanes/2512/d3008455/source/monodroid/src/Mono.Android/src/Java.Interop/TypeManager.cs:277
  --- End of inner exception stack trace ---
  at at (wrapper dynamic-method) System.Object:af0a91a8-6100-4d3f-9981-1bb807595da4 (intptr,intptr,intptr)
  at at (wrapper native-to-managed) System.Object:af0a91a8-6100-4d3f-9981-1bb807595da4 (intptr,intptr,intptr)

Anyone has an idea ?

My Entry code is below:

ExtendedEntry.cs

public class ExtendedEntry : Entry
    {
        /// <summary>
        /// The MaxLength property
        /// </summary>
        public static readonly BindableProperty MaxLengthProperty =
            BindableProperty.Create("MaxLength", typeof(int), typeof(ExtendedEntry), int.MaxValue);

        /// <summary>
        /// Gets or sets the MaxLength
        /// </summary>
        public int MaxLength
        {
            get { return (int)this.GetValue(MaxLengthProperty);}
            set { this.SetValue(MaxLengthProperty, value); }
        }

        public ExtendedEntry() { }
    }

ExtendedEntryRenderer.cs

public class ExtendedEntryRenderer_Android : EntryRenderer
    {
        public ExtendedEntryRenderer_Android() { }

        protected override void OnElementChanged (ElementChangedEventArgs<Entry> e)
        {
            base.OnElementChanged (e);

            var formView = (ExtendedEntry)this.Element;
            var nativeView = (EditText) this.Control;

            if(Control != null)
            {
                SetMaxLength(formView);
            }
        }

        /// <summary>
        /// Sets the MaxLength characteres.
        /// </summary>
        /// <param name="view">The view.</param>
        private void SetMaxLength(ExtendedEntry view)
        {
            Control.SetFilters(new IInputFilter[] { new InputFilterLengthFilter(view.MaxLength) });
        }
    }

Thanks

Best regards,

Armand


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>