私はXamarin.Androidでスワイプカードビューを実装しています。 RatingCardAdapterからすべてのカードをスワイプした後、スワイプカードビューをリセットするイベントを発生させています。初めてイベントがnullでなくスワイプカードがリセットされますが、2回目の試行ではイベントハンドラはnullを返します。その結果、私はの値を設定することはできませんshouldResetSwipe。どうすればこの問題を解決できますか?nullを返すイベントハンドラc#?
アダプタ
public class RatingCardAdapter : BaseCardAdapter
{
private Context context;
public event EventHandler OnLastCardSwiped;
public RatingCardAdapter(Context context, SwipeCardsView SwipeView)
{
this.context = context;
this.SwipeView = SwipeView;
SwipeView.SetCardsSlideListener(this);
}
public void OnCardVanish(int p0, SwipeCardsView.SlideType p1)
{
if (p0 == (Count - 1)) // p0 becomes 4 when last card is swiped
{
if (OnLastCardSwiped != null) //becomes null when rating adapter called 2nd time
OnLastCardSwiped(this, new OnLastCardSwipeArgs
{
shouldResetSwipe = true });
}
}
public class OnLastCardSwipeArgs : EventArgs
{
public bool shouldResetSwipe { get; set; }
}
活動
private SwipeCardsView swipeCardsView;
RatingCardAdapter ratingCardAdapter;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.activity_rating_session);
swipeCardsView = FindViewById<SwipeCardsView>
(Resource.Id.swipeCardsRating);
swipeCardsView.RetainLastCard(false);
swipeCardsView.EnableSwipe(true);
setSwipeData();
}
void setSwipeData() {
ratingCardAdapter = new RatingCardAdapter(this, swipeCardsView);
swipeCardsView.SetAdapter(ratingCardAdapter);
ratingCardAdapter.OnLastCardSwiped += (sender, e) =>
{
if (e.shouldResetSwipe)
{
Console.WriteLine("restart set " + e.shouldResetSwipe);
restartSwipeCard();
}};
}
void restartSwipeCard()
{
Console.WriteLine("restartswipe");
ratingCardAdapter = new RatingCardAdapter(this,swipeCardsView);
swipeCardsView.SetAdapter(ratingCardAdapter);
}
は、あなたに由良をありがとうあなたは人生の救世主です。 –
あなたを助けてくれてうれしい!正しいと答えてマークすることを忘れないでください) – Yura