2017-07-19 8 views
1

Horizo​​ntalScrollViewに2つのRecyclerViewが埋め込まれたAndroid Appがあります。一番上のRecyclerViewにはカテゴリがあり、カテゴリを選択すると、一番下のRecyclerViewにそのカテゴリのアイテムが一覧表示されます。選択したカテゴリを検出するために、Touchイベントを使用しようとしています。 EditTextがタッチイベントを取得すると、その行が選択されます。この部分は素晴らしい作品です。問題は、カテゴリリストの一部のフィールドを編集できる必要があることです。私がEditTextでTouchイベントをバインドすると、EditTextはクリックしたときにフォーカスを取得しません。 FocusChangedイベントを使用してみましたが、水平方向にスクロールすると、先頭のRecyclerViewのフォーカスが最初のカテゴリのEditTextに設定され、選択されたカテゴリが変更されます。 MvvmCrossのTouchイベントをバインドして、バインドされたコントロールがフォーカスを取得させる方法がありますか?MvvmCrossバインディングタッチイベントはMvxItemTemplateに焦点を当てない

これは私の項目テンプレートのレイアウトです:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:local="http://schemas.android.com/apk/res-auto" 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:paddingTop="2dp" 
    android:paddingBottom="2dp" 
    local:MvxBind="This View"> 
    <TextView 
     android:layout_width="300dp" 
     android:layout_height="wrap_content" 
     style="@style/TableEditText" 
     local:MvxBind="Text Name; LongClick Name_LongClick; Touch Touch" 
     android:id="@+id/txtName" /> 
    <EditText 
     android:layout_width="110dp" 
     android:layout_height="wrap_content" 
     style="@style/TableEditText" 
     android:inputType="numberDecimal|numberSigned" 
     android:selectAllOnFocus="true" 
     local:MvxBind="Text Cubes, Converter=FloatToStringConverter; Touch Touch" 
     android:id="@+id/txtCubes" /> 
    <EditText 
     android:layout_width="110dp" 
     android:layout_height="wrap_content" 
     style="@style/TableEditText" 
     android:inputType="numberDecimal|numberSigned" 
     android:selectAllOnFocus="true" 
     local:MvxBind="Text Weight, Converter=IntToStringConverter; Touch Touch" 
     android:id="@+id/txtWeight" /> 
    <EditText 
     android:layout_width="500dp" 
     android:layout_height="wrap_content" 
     style="@style/TableEditText" 
     android:inputType="textCapSentences" 
     local:MvxBind="Text Note; Touch Touch" 
     android:id="@+id/txtNote" /> 
    <ImageButton 
     android:src="@drawable/ic_action_delete" 
     android:scaleType="fitCenter" 
     android:padding="3dp" 
     android:layout_width="40dp" 
     android:layout_height="40dp" 
     android:layout_marginLeft="5dp" 
     android:layout_marginRight="5dp" 
     android:layout_gravity="center" 
     local:MvxBind="Click DeleteClicked" 
     android:id="@+id/btnDeleteCategory" /> 
</LinearLayout> 

これは、タッチイベントのための私のフックです:

public MvxCommand Touch 
    { 
     get 
     { 
      return new MvxCommand(() => 
      { 
       SurveyView act = (Mvx.Resolve<IMvxAndroidCurrentTopActivity>().Activity as SurveyView) ?? null; 
       if (act != null) 
       { 
        act.SetCurrCategory(this); 
       } 
      }); 
     } 
    } 

これは、タッチイベントのバインディングの私の習慣です:

public class MvxViewTouchBinding 
    : MvxAndroidTargetBinding 
{ 
    private readonly View _view; 
    private IMvxCommand _command; 

    public MvxViewTouchBinding(View view) : base(view) 
    { 
     _view = view; 
     _view.Touch += ViewOnTouch; 
    } 

    private void ViewOnTouch(object sender, View.TouchEventArgs eventArgs) 
    { 
     if (_command != null) 
     { 
      _command.Execute(); 
     } 
    } 

    public override void SetValue(object value) 
    { 
     _command = (IMvxCommand)value; 
    } 

    protected override void Dispose(bool isDisposing) 
    { 
     if (isDisposing) 
     { 
      _view.Touch -= ViewOnTouch; 
     } 
     base.Dispose(isDisposing); 
    } 

    protected override void SetValueImpl(object target, object value) 
    { 
    } 

    public override Type TargetType 
    { 
     get { return typeof(IMvxCommand); } 
    } 

    public override MvxBindingMode DefaultMode 
    { 
     get { return MvxBindingMode.OneWay; } 
    } 
} 

これはSetup.csにあります

 registry.RegisterCustomBindingFactory<View>("Touch", 
                view => new MvxViewTouchBinding(view)); 
+1

これを試してください - https://stackoverflow.com/a/36360795/2754727 – pnavk

+2

'eventArgs.Handled = false; 'を設定してみてください – Cheesebaron

+0

@Cheesebaronそれをしました!おかげでチーズ! –

答えて

0

私はにViewOnTouchハンドラを変更する必要がありました:trueに

private void ViewOnTouch(object sender, View.TouchEventArgs eventArgs) 
    { 
     eventArgs.Handled = false; 

     if (_command != null) 
     { 
      _command.Execute(); 
     } 
    } 

どうやら取扱デフォル​​トとこれはこれが呼び出された後にイベントのチェーンが終了します。この値をfalseに設定すると、システムはイベントが適切に処理されていないため、次のハンドラを1行ずつ呼び出します。私は後続のハンドラがフォーカスを設定すると推測しています。ありがとう@Cheesebaron

関連する問題