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