通过点击项目获取MvxListView的项目位置
如何通过单击此MvxListView的行获取项目位置?通过点击项目获取MvxListView的项目位置,listview,xamarin.android,Listview,Xamarin.android,如何通过单击此MvxListView的行获取项目位置?int cposition=0;//您的全局变量 <Mvx.MvxListView android:id="@+id/mylist" android:layout_width="fill_parent" android:layout_height="wrap_content" android:scrollbars="horizontal" local:MvxBind="ItemsSource pr
int cposition=0;//您的全局变量
<Mvx.MvxListView
android:id="@+id/mylist"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="horizontal"
local:MvxBind="ItemsSource productlist"
local:MvxItemTemplate="@layout/productitem" />
setOnItemClickListener(新的OnItemClickListener(){
@凌驾
public void onItemClick(适配器视图a、视图v、内部位置、长id){
位置=位置;
}
});
不幸的是,MvxListView的工作方式在处理项目单击事件和分派到您的命令时吞没了项目位置。见和
您可以将MvxListView子类化,并重写ExecuteCommandOnItem()方法以捕获位置
比如:
公共类MyMvxListView:MvxListView
{
//在此处添加构造函数
//属性来捕获位置
公共int位置{get;private set;}
public override void ExecuteCommandOnItem(ICommand命令,int位置)
{
//存储位置
位置=位置;
//调用基类
base.ExecuteCommandOnItem(命令、位置);
}
}
我没有使用适配器,而是使用ItemTemplate绑定数据
int cposition =0; // your global variable
listview.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
cposition =position;
}
});