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>
這是接近的問題,如http://stackoverflow.com/questions/14443364/unable-to-get-listview-itemclick-to-be-called-in-monodroid – Stuart 2014-11-05 17:14:51
它是相似的,但我想知道這是真的需要爲此創建自定義適配器?我試圖在itemView.xml中設置這些屬性,但沒有運氣 – 2014-11-06 08:55:02
我認爲你可能只是面臨一個Android問題 - 搜索周圍的問與答像http://stackoverflow.com/questions/6703390/listview-setonitemclicklistener-not-working-通過添加按鈕 - 如果你嘗試了一些東西,那麼請編輯問題以提供更多信息(評論很難理解) – Stuart 2014-11-06 12:09:45