Android 带拖放和按钮的可排序ListView,如何知道按钮上的list.position
我有一个来自以下代码的可排序列表视图:Android 带拖放和按钮的可排序ListView,如何知道按钮上的list.position,android,listview,xamarin,xamarin.android,draggable,Android,Listview,Xamarin,Xamarin.android,Draggable,我有一个来自以下代码的可排序列表视图: if (!editImageButton.HasOnClickListeners) { editImageButton.Click += delegate { ((MainActivity)context).ShowEditPhaseDialog(position); };
if (!editImageButton.HasOnClickListeners)
{
editImageButton.Click += delegate
{
((MainActivity)context).ShowEditPhaseDialog(position);
};
}
在每一行我有一个按钮,我需要知道列表。每次我点击按钮的位置。
在实现drag n drop listview之前,我是这样获得位置的:
if (!editImageButton.HasOnClickListeners)
{
editImageButton.Click += delegate
{
((MainActivity)context).ShowEditPhaseDialog(Int32.Parse(editImageButton.Tag.ToString()));
};
}
在我的ListViewAdapter中,我使用以下代码:
if (!editImageButton.HasOnClickListeners)
{
editImageButton.Click += delegate
{
((MainActivity)context).ShowEditPhaseDialog(position);
};
}
在我的活动中:
public void ShowEditPhaseDialog(int phasePos)
{
var builder = new AlertDialog.Builder(this);
userInput = new EditText(this);
userInput.Text = data[phasePos].PhaseName;
builder.SetTitle("Phase Edit");
builder.SetMessage("Edit or Delete a phase");
builder.SetPositiveButton("Save edit", (s, ex) => { EditPhase(userInput.Text, phasePos); });
builder.SetView(userInput);
builder.SetCancelable(false);
builder.SetNegativeButton("Cancel", (s, ex) => { HideKeyboard(userInput); });
builder.SetNeutralButton("Delete", (s, ex) => { RemovePhase(phasePos); });
dialog = builder.Create();
dialog.Show();
ShowKeyboard(userInput);
}
但是现在,在实现了可拖动适配器之后,每当我更改行的位置时,onbutton clicklistener与旧位置保持相同。我怎样才能解决这个问题
DragableListAdapter具有交换项目的功能:
public void SwapItems(int indexOne, int indexTwo)
{
var oldValue = Items[indexOne];
Items[indexOne] = Items[indexTwo];
Items[indexTwo] = oldValue;
mMobileCellPosition = indexTwo;
NotifyDataSetChanged();
}
通过使用按钮解决。标记存储位置并通过以下方式发送位置:
if (!editImageButton.HasOnClickListeners)
{
editImageButton.Click += delegate
{
((MainActivity)context).ShowEditPhaseDialog(Int32.Parse(editImageButton.Tag.ToString()));
};
}