3

スナックバーで元に戻すをクリックした後、スワイプを元に戻そうとしています (リセットbackground.setboundsxmark.setboundsて 0,0,0,0 にします)。

if then setbounds を 0,0,0,0 にclearViewブール値を導入しようとしましたが、まだ機能しません。onChildDrawviewBeingCleared == true

元に戻すをクリックした後、ビューをリセットしたり、赤い背景とアイコンを削除したりするにはどうすればよいですか?

いくつかの助けをいただければ幸いです。

@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
    final int position = viewHolder.getAdapterPosition();

    View view = viewHolder.itemView;
    final TextView orderID = (TextView) view.findViewById(R.id.order_ID);

    // showing snack bar with Undo option

    Snackbar.make(view, "removed from cart!", 3000)
            .addCallback(new Snackbar.Callback() {
                @Override
                public void onDismissed(Snackbar snackbar1, int event) {
                    if (event == Snackbar.Callback.DISMISS_EVENT_TIMEOUT) {
                        // Snackbar closed on its own
                        mAdapter.deleteItem(position, orderID.getText().toString());
                    }
                }

            })
            .setActionTextColor(Color.YELLOW)
            .setAction("UNDO", new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    // undo is selected, restore the deleted item
                    //mAdapter.restoreItem(deletedItem, deletedIndex);
                    viewBeingCleared = true;
                    onClicked = true;
                    Log.d(TAG, "Undo clicked");
                }
            })
            .show();
}

@Override
public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
    super.clearView(recyclerView, viewHolder);
    background.setBounds(0,0,0,0);
    xMark.setBounds(0,0,0,0);
    viewBeingCleared = true;
}

@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
    View itemView = viewHolder.itemView;

    // not sure why, but this method get's called for viewholder that are already swiped away
    if (viewHolder.getAdapterPosition() == -1) {
        // not interested in those
        return;
    }

    if (!initiated) {
        init();
    }

    if (viewBeingCleared) {
        viewBeingCleared=false;
    } else {
        // draw red background
        background.setBounds(itemView.getRight() + (int) dX, itemView.getTop(), itemView.getRight(), itemView.getBottom());
        background.draw(c);

        // draw x mark
        int itemHeight = itemView.getBottom() - itemView.getTop();
        int intrinsicWidth = xMark.getIntrinsicWidth();
        int intrinsicHeight = xMark.getIntrinsicWidth();

        int xMarkLeft = itemView.getRight() - xMarkMargin - intrinsicWidth;
        int xMarkRight = itemView.getRight() - xMarkMargin;
        int xMarkTop = itemView.getTop() + (itemHeight - intrinsicHeight) / 2;
        int xMarkBottom = xMarkTop + intrinsicHeight;


        xMark.setBounds(xMarkLeft, xMarkTop, xMarkRight, xMarkBottom);
        xMark.draw(c);

    }

    super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
}

ループが機能しない 元に戻す

4

0 に答える 0