2014-11-05 19 views
0

我有一個綁定Click事件對我的項目MvxGridView(我正在使用ItemClick綁定)的問題。ItemClick未綁定在MvxGridView的按鈕上

所有渲染都很好,而且東西。當我使用TextView時,我的GoClick方法正常啓動。但是當我在我的ItemTemplateView中將TextView更改爲Button時,則不再調用GoClick方法。

根據this答案(選項編號1)都應該正常工作。但在Button的情況下,它不。

任何幫助表示讚賞,我卡在這裏。

我的視圖模型:

public class MyViewModel : MvxViewModel 
{ 
    private IEnumerable<MyListItem> items; 

    public MyViewModel() 
    { 
     this.items = new List<MyListItem> 
     { 
      new MyListItem {Name = "Item1"}, 
      new MyListItem {Name = "Item2"}, 
     }; 
    } 

    public IEnumerable<MyListItem> Items 
    { 
     get { return this.items; } 
    } 

    public ICommand SelectItem 
    { 
     get { return new MvxCommand<MyListItem>(this.GoClick);} 
    } 

    public void GoClick(MyListItem item) 
    { 
     //doSomething 
    } 
} 

我與MvxGridView佈局:

<?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:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:background="@color/black" 
    > 
     <Mvx.MvxGridView 
      android:layout_width="300dp" 
      android:layout_height="match_parent" 
      android:gravity="center" 
      android:horizontalSpacing="10dp" 
      android:numColumns="3" 
      android:stretchMode="columnWidth" 
      android:verticalSpacing="10dp" 
      local:MvxItemTemplate="@layout/itemtemplateview" 
      local:MvxBind="ItemsSource Items; ItemClick SelectItem" 
      /> 
</LinearLayout> 

ItemTemplateView如果你想要一個click事件(與TextView正常工作)

<?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:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    > 
     <TextView 
      android:layout_height="wrap_content" 
      android:layout_width="match_parent" 
      local:MvxBind="Text Name" 
      /> 
     <!-- CLICK ON THIS BUTTON DOES NOT WORK --> 
     <!-- 
     <Button 
      android:layout_height="wrap_content" 
      android:layout_width="match_parent" 
      local:MvxBind="Text Name" 
      /> 
     --> 
</LinearLayout> 
+0

這是接近的問題,如http://stackoverflow.com/questions/14443364/unable-to-get-listview-itemclick-to-be-called-in-monodroid – Stuart 2014-11-05 17:14:51

+0

它是相似的,但我想知道這是真的需要爲此創建自定義適配器?我試圖在itemView.xml中設置這些屬性,但沒有運氣 – 2014-11-06 08:55:02

+0

我認爲你可能只是面臨一個Android問題 - 搜索周圍的問與答像http://stackoverflow.com/questions/6703390/listview-setonitemclicklistener-not-working-通過添加按鈕 - 如果你嘗試了一些東西,那麼請編輯問題以提供更多信息(評論很難理解) – Stuart 2014-11-06 12:09:45

回答

0

按鈕,並且您正在使用「瑞士」綁定,請使用:

local:MvxBind="Click DoNameClick"/> 

代替

local:MvxBind="Text Name" 

退房文檔:https://github.com/MvvmCross/MvvmCross/wiki/databinding

注 - 你必須有一個公共的 「DoNameClick」 吸氣劑您的視圖模型!