2014-10-03 6 views
0

내 도메인 모델의 값을 기반으로 다른 목록 항목 템플릿이있는 MvxListView가 있습니다. 각 템플릿에는 click 이벤트에서 뷰 모델에 바인딩되는 버튼이 있습니다. MvxAdapter 클래스를 사용하여 도메인 모델 값을 기반으로 올바른 템플릿을 반환했으며 완벽하게 작동합니다. 그러나 어떤 이유로 인해 템플릿 버튼 클릭 이벤트가 뷰 모델에 전파되지 않습니다. 동일한보기에서 다른 버튼을 사용하고 클릭 이벤트에 바인딩하면됩니다.MvxAdapter Click Events Not Firing

내 MvxList : 사용되는 두 개의 템플릿

<Mvx.MvxListView 
    local:MvxBind="ItemsSource MessageItems; ItemClick TextMessageSelectedCommand" 
    local:MvxItemTemplate="@layout/template_message_item_inbound" 
    android:id="@+id/MessageList" 
    android:divider="@drawable/list_divider_selector" 
    android:choiceMode="singleChoice" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:layout_above="@+id/input" 
    style="@style/MessageListStyle" /> 

하나 :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:local="http://schemas.android.com/apk/res-auto" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"> 
<TextView 
    android:text="BP" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:layout_width="65dp" 
    android:layout_height="65dp" 
    android:id="@+id/txtInitials" 
    local:MvxBind="Text From, Converter=NameToInitials" 
    android:background="@drawable/message_badge_inbound" 
    android:layout_gravity="center" 
    android:gravity="center" 
    style="@style/MessageUserBadge" /> 
<TextView 
    android:text="Small Text" 
    android:textAppearance="?android:attr/textAppearanceSmall" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_toRightOf="@+id/txtInitials" 
    android:background="@drawable/speech_bubble_inbound" 
    local:MvxBind="Text Message" 
    android:id="@+id/txtMessage" 
    android:layout_marginRight="65dp" /> 
<TextView 
    android:text="12:53 pm" 
    android:textAppearance="?android:attr/textAppearanceSmall" 
    android:layout_width="65dp" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/txtInitials" 
    local:MvxBind="Text Time, Converter=DateToString, ConverterParameter='t'" 
    android:id="@+id/txtTime" 
    style="@style/MessageTime" 
    android:gravity="center" /> 
<ImageButton 
    android:text="Button" 
    local:MvxBind="Click DeleteMessageCommand" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/btnDeleteMessage" 
    android:src="@drawable/ic_action_delete" 
    android:layout_alignParentRight="true" 
    android:layout_centerInParent="true" 
    android:tag="InboundDeleteButton" /> 

모델 값을 기반으로 템플릿을 선택 내 사용자 정의 어댑터 클래스 :

 public class CustomAdapter : MvxAdapter 
    { 
     public CustomAdapter(Context context, IMvxAndroidBindingContext bindingContext) 
      : base(context, bindingContext) 
     { 
     } 

     public override int GetItemViewType(int position) 
     { 
      var item = GetRawItem(position); 
      if (item is TextMessage && (item as TextMessage).Direction == MessageDirection.Inbound) 
       return 0; 
      return 1; 
     } 

     public override int ViewTypeCount 
     { 
      get { return 2; } 
     } 
     protected override View GetBindableView(View convertView, object source, int templateId) 
     { 
      if (source is TextMessage && (source as TextMessage).Direction == MessageDirection.Inbound) 
      { 
       templateId = Resource.Layout.template_message_item_inbound; 
      } 
      else if (source is TextMessage && (source as TextMessage).Direction == MessageDirection.Outbound) 
      { 
       templateId = Resource.Layout.template_message_item_outbound; 
      } 
      return base.GetBindableView(convertView, source, templateId); 
     } 
    } 

내보기 모델에서 나는 명령 패턴을 사용하여 이벤트 리스너를 설정했다.

public ICommand DeleteMessageCommand 
    { 
     get 
     { 
      _deleteMessageCommand = _deleteMessageCommand ?? new MvxCommand(HandleDeleteMessage); 
      return _deleteMessageCommand; 
     } 
    } 

    private void HandleDeleteMessage() 
    { 

    } 

답변

1

MvxMessage를 사용하고 해당 메시지를 내보기 모델에 등록하여 해결책을 찾았습니다. 나는 Kiliman에서 예제 코드를 따랐다. 다른 사람의 링크 stackoverflow post here

+0

차갑다. 나는 너를 그 지점으로 안내하려고했다. – Kiliman