Android 使用Icommand在Listview的ListItem中单击按钮
我在MvxListView中有带删除按钮的Listitems。我想删除单击删除按钮的特定行。如何使用Icommand实现该单击事件?扩展Android 使用Icommand在Listview的ListItem中单击按钮,android,listview,xamarin,mvvmcross,Android,Listview,Xamarin,Mvvmcross,我在MvxListView中有带删除按钮的Listitems。我想删除单击删除按钮的特定行。如何使用Icommand实现该单击事件?扩展MvxListView以具有DeleteClick属性: ICommand DeleteClik 将此属性绑定到所需的命令: local:MvxBind="DeleteClick MyDeleteCommand" 创建一个自定义适配器,该适配器将引用此DeleteClick命令,并将其绑定到GetView方法上视图的click事件: public overri
MvxListView
以具有DeleteClick
属性:
ICommand DeleteClik代码>
将此属性绑定到所需的命令:
local:MvxBind="DeleteClick MyDeleteCommand"
创建一个自定义适配器,该适配器将引用此DeleteClick
命令,并将其绑定到GetView
方法上视图的click事件:
public override View GetView (int position, View view, ViewGroup parent)
{
//TODO: Ensure view is not null, call base method and convert to proper type
var deleteButton = view.FindViewById<Button>(Resource.Id.buttonId);
deleteButton.Click += (sender, e) => {
if(_deleteCommand != null && _deleteCommand.CanExecute())
{
//TODO: Cast to your type
_deleteCommand(GetRawItem(position));
}
}
}
public覆盖视图GetView(int位置、视图视图、视图组父视图)
{
//TODO:确保视图不为null,调用base方法并转换为正确的类型
var deleteButton=view.findviewbyd(Resource.Id.buttonId);
删除按钮。单击+=(发件人,e)=>{
if(_deleteCommand!=null&&u deleteCommand.CanExecute())
{
//TODO:按您的类型转换
_deleteCommand(GetRawItem(位置));
}
}
}
请看我对这个问题的回答:您能更精确一点吗?因为我也有同样的问题,我不明白你的答案。。