2017-08-29 15 views
0

が返されます。そのため、スキャン入力を受け入れるための包括的なコントロールを設定してから、テキストが変更されたときにいくつかの機能を実行します。私はEditTextにITextWatcherを実装しました。そのコントロールを持つフラグメントにナビゲートすると、エラーが発生します。ここではコントロールに必要な要素EditTextでITextWatcherを実装するとエラー

public class ScannerEditText : EditText, View.IOnKeyListener, View.IOnFocusChangeListener, ITextWatcher 
{ 
    private void Init() 
    { 
     this.Focusable = true; 
     this.FocusableInTouchMode = true; 
     //this.SetOnKeyListener(this); 
     this.AddTextChangedListener(this); 
     //this.OnFocusChangeListener = this; 
    } 

    private Timer _refreshTimer = null; 
    private string _priorText = null; 

    public ScannerEditText(Context context) 
     : base(context) 
    { 
     this.Init(); 
    } 

    public ScannerEditText(Context context, IAttributeSet attrs) 
     :base(context, attrs) 
    { 
     this.Init(); 
    } 

    public ScannerEditText(Context context, IAttributeSet attrs, int defStyleAttr) 
     :base(context, attrs, defStyleAttr) 
    { 
     this.Init(); 
    } 

    public ScannerEditText(Context context, IAttributeSet attrs, int defStyleAttr, int defStyleRes) 
     :base(context, attrs, defStyleAttr, defStyleRes) 
    { 
     this.Init(); 
    } 

    void ITextWatcher.AfterTextChanged(IEditable s) 
    { 
     if (this._refreshTimer != null) this._refreshTimer.Dispose(); 
     this._refreshTimer = new Timer(delegate (object state) 
     { 
      this._refreshTimer = null; 
      OnUpdateData(this, new EventArgs()); 
     }, false, 500, 0); 
    } 

    void ITextWatcher.BeforeTextChanged(ICharSequence s, int start, int count, int after) 
    { 
     this._priorText = s.ToString(); 
    } 

    void ITextWatcher.OnTextChanged(ICharSequence s, int start, int before, int count) 
    { 
     string newText = s.ToString(); 

     //if isEmpty do not advance 
     if (string.IsNullOrWhiteSpace(newText)) 
      return; 

     if (newText.Length < this._priorText.Length) 
     { 
      //if 1 character deleted do not advance 
      if (newText == this._priorText.Substring(0, this._priorText.Length - 1)) 
       return; 
     } 
     else if (this._priorText.Length < newText.Length) 
     { 
      //if 1 character added do not advance 
      if (newText.Substring(0, newText.Length - 1) == this._priorText) 
       return; 
     } 

     UIUtil.HideKeyboard((Activity)this.Context, (View)this); 

     ((View)this.Parent).FindViewById<EditText>(this.NextFocusRightId).RequestFocus(); 
    } 
} 

だそれから私は、任意のフラグメントへこのコントロールを移動して、次のエラーを取得: System.NotSupportedException:タイプのインスタンスをアクティブにできませんAndroidMobileBarcodeForMieTrakAPI.Xamarin.Controls.ScannerEditTextからネイティブ柄今

私はITextWatcherインターフェイスを削除し、他の実装のすべては、私が検索した後に見ている

すべてがほとんど少し異なるオベの作品のjavaで動作するかどうかメンバーを実装するのではなく、メンバーを争っています。あなたがIntPtrJniHandleOwnershipでコンストラクタを公開する必要が

答えて

1

protected ScannerEditText(IntPtr javaReference, JniHandleOwnership transfer) 
    : base(javaReference, transfer) 
{ 
} 
+0

素晴らしいです、ありがとうございました。 –

関連する問題