Ich erstelle eine MvxRecyclerview mit Swipe, ich brauche den gestickt Artikel der recyclerview zu entfernen, aber wenn ich den Swipe machen, entfernen Sie den Artikel und danach erscheint ein anderes Element im unteren recyclingview.entfernen Sie einen Artikel in einer Recyclerview mit Swipe in mvvmcross
Nombre.cs
public class Nombre
{
public string _name;
public string name
{
get { return _name; }
}
}
RecyclerViewModel.cs
public class RecyclerViewModel : BaseViewModel
{
//private IList<Nombre> Items;
NombreGenesisService lista;
public RecyclerViewModel()
{
//Nombres lista = new Nombres();
lista = new NombreGenesisService();
Items = new List<Nombre>
{
new Nombre()
{
_name = "sebastian",
},
new Nombre()
{
_name = "Natalia",
},
new Nombre()
{
_name = "Angelica",
},
new Nombre()
{
_name = "Octavio",
},
};
}
private List<Nombre> _items;
public List<Nombre> Items
{
get { return _items; }
set
{
_items = value;
RaisePropertyChanged(() => Items);
}
}
}
}
RecyclerViewFragment.cs
public class RecyclerViewFragment : BaseFragment<RecyclerViewModel>
{
protected override int FragmentId
{
get
{
return Resource.Layout.fragment_example_recyclerview;
}
}
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
var ignore = base.OnCreateView(inflater, container, savedInstanceState);
var recyclerView = ignore.FindViewById<MvxRecyclerView>(Resource.Id.my_recycler_view);
if (recyclerView != null)
{
recyclerView.HasFixedSize = true;
var layoutManager = new LinearLayoutManager(Activity);
recyclerView.SetLayoutManager(layoutManager);
ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(recyclerView.GetAdapter());
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callback);
itemTouchHelper.AttachToRecyclerView(recyclerView);
recyclerView.SetItemAnimator(new DefaultItemAnimator());
}
return ignore;
}
public override void OnDestroyView()
{
base.OnDestroyView();
}
}
SimpleItemTouchHelperCallback.cs
class SimpleItemTouchHelperCallback : ItemTouchHelper.Callback
{
// private RecyclerView.Adapter adapter;
private readonly RecyclerView.Adapter _adapter;
RecyclerViewModel lista;
NombreGenesisService lista2;
public SimpleItemTouchHelperCallback(RecyclerView.Adapter adapter)
{
_adapter = adapter;
lista = new RecyclerViewModel();
}
public override int GetMovementFlags(RecyclerView p0, RecyclerView.ViewHolder p1)
{
int dragFlags = ItemTouchHelper.Up | ItemTouchHelper.Down;
int swipeFlags = ItemTouchHelper.Start | ItemTouchHelper.End;
return MakeMovementFlags(dragFlags, swipeFlags);
}
public override bool OnMove(RecyclerView p0, RecyclerView.ViewHolder p1, RecyclerView.ViewHolder p2)
{
_adapter.NotifyItemMoved(p1.AdapterPosition, p2.AdapterPosition);
return true;
}
public override void OnSwiped(RecyclerView.ViewHolder p0, int p1)
{
lista.Items.RemoveAt(p0.AdapterPosition);
_adapter.NotifyItemRemoved(p0.AdapterPosition);
}
}
fragment_example_recyclerview.axml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<MvxRecyclerView
android:id="@+id/my_recycler_view"
android:scrollbars="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#CCCCCC"
local:MvxBind="ItemsSource Items;"
local:MvxItemTemplate="@layout/item_name" />
Ich habe so etwas schon einmal gemacht. Werfen Sie einen Blick auf meine Probe hier: https://github.com/martijn00/XamarinItemTouchHelper – Martijn00
hat nicht geholfen, danke – pikipichiummm