[英]Sortable ListView with Drag n Drop and buttons, how to know list.position on button press
I have a Sortable ListView from this code: 我从此代码有一个可排序的ListView:
https://github.com/pnavk/Drag-and-Drop-ListView https://github.com/pnavk/Drag-and-Drop-ListView
On each row i have a button, i need to know the list.position every time i click on the button. 在每一行上我都有一个按钮,每次单击按钮时我都需要知道list.position。 Before implementing the drag n drop listview i was getting the position in this way:
在实现drag n drop listview之前,我是以这种方式获得位置的:
In my ListViewAdapter i use this code: 在我的ListViewAdapter中,我使用以下代码:
if (!editImageButton.HasOnClickListeners)
{
editImageButton.Click += delegate
{
((MainActivity)context).ShowEditPhaseDialog(position);
};
}
and in my activity: 在我的活动中:
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);
}
But now after implementing the draggable adapter, every time i change the position of the row, the onbutton clicklistener remain the same with the old position. 但是现在在实现可拖动适配器之后,每次我更改行的位置时,onclick clicklistener都与旧位置保持不变。 how i can solve this problem?
我该如何解决这个问题?
DraggableListAdapter has this function for swapping items: DraggableListAdapter具有用于交换项目的此功能:
public void SwapItems(int indexOne, int indexTwo)
{
var oldValue = Items[indexOne];
Items[indexOne] = Items[indexTwo];
Items[indexTwo] = oldValue;
mMobileCellPosition = indexTwo;
NotifyDataSetChanged();
}
Solved by using button.Tag to store the position and send the position in this way: 通过使用button.Tag解决此问题,以存储位置并通过以下方式发送位置:
if (!editImageButton.HasOnClickListeners)
{
editImageButton.Click += delegate
{
((MainActivity)context).ShowEditPhaseDialog(Int32.Parse(editImageButton.Tag.ToString()));
};
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.