Recycler View Scroll无响应

时间:2015-12-16 10:24:19

标签: android android-recyclerview android-cardview

我正在使用回收站视图在我的Android应用中显示一组卡片。我已经选择使用ItemTouchHelper.SimpleCallback水平滚动回收器视图和垂直滑动功能,以从回收器视图中删除该项目。 然而,在两次连续滑动之后,我的回收者视图变得没有响应,即花时间来响应滚动手势。什么使回收者滚动缓慢?

以下是我的适配器类

public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.TTViewHolder> {
    List<TroubleTicketGui> troubleTicketGuis;
    List<TroubleTicketGui> swipedTroubleTickets;
    TroubleTicketHome troubleTicketHome = new TroubleTicketHome();

    public RecyclerViewAdapter(List<TroubleTicketGui> troubleTicketGuis) {
        this.troubleTicketGuis = troubleTicketGuis;
        this.swipedTroubleTickets = new LinkedList<>();
    }

    @Override
    public int getItemCount() {
        return troubleTicketGuis.size();
    }

    @Override
    public TTViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.cardview, viewGroup, false);
        TTViewHolder ttViewHolder = new TTViewHolder(v);
        return ttViewHolder;
    }

    @Override
    public void onBindViewHolder(TTViewHolder ttViewHolder, int i) {
        ttViewHolder.NOCRefernceNumber.setText(troubleTicketGuis.get(i).getNOCRefernceNumber());
        ttViewHolder.title.setText(troubleTicketGuis.get(i).getTitle());
        ttViewHolder.severity.setImageResource(troubleTicketGuis.get(i).getSeverity());
    }

    @Override
    public void onAttachedToRecyclerView(RecyclerView recyclerView) {
        super.onAttachedToRecyclerView(recyclerView);
    }


    public void onItemRemove(final int adapterPosition, final RecyclerView recyclerView, final List<TTOverviewGui> ttOverviewGuis, final TroubleTicketHome troubleTicketHome) {
        final TroubleTicketGui troubleTicketGui = troubleTicketGuis.get(adapterPosition);
        final TTOverviewGui ttOverviewGui = ttOverviewGuis.get(adapterPosition);
        String status = (troubleTicketGui.getTtStatus() == TTStatus.ONHOLD) ? TTStatus.OPEN.name() : TTStatus.ONHOLD.name();
        Snackbar snackbar = Snackbar
                .make(recyclerView, " MARKED AS " + status, Snackbar.LENGTH_LONG)
                .setAction("UNDO", new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        troubleTicketGuis.add(adapterPosition, troubleTicketGui);
                        swipedTroubleTickets.remove(troubleTicketGui);
                        ttOverviewGuis.add(adapterPosition, ttOverviewGui);
                        notifyItemInserted(adapterPosition);
                        troubleTicketHome.prepareTicketGui(ttOverviewGuis);
                        recyclerView.scrollToPosition(adapterPosition);
                    }
                });
        snackbar.setCallback(new Snackbar.Callback() {
            @Override
            public void onDismissed(Snackbar snackbar, int event) {
                super.onDismissed(snackbar, event);

            }
        });
        snackbar.show();
        troubleTicketGuis.remove(adapterPosition);
        ttOverviewGuis.remove(adapterPosition);
        swipedTroubleTickets.add(troubleTicketGui);
        notifyItemRemoved(adapterPosition);
    }

    public static class TTViewHolder extends RecyclerView.ViewHolder {
        CardView cv;
        TextView NOCRefernceNumber;
        TextView title;
        ImageView severity;

        TTViewHolder(final View itemView) {
            super(itemView);
            cv = (CardView) itemView.findViewById(R.id.cv);
            this.NOCRefernceNumber = (TextView) itemView.findViewById(R.id.tt_nocrefnumber);
            this.title = (TextView) itemView.findViewById(R.id.tt_title);
            this.severity = (ImageView) itemView.findViewById(R.id.tt_severity);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent = new Intent(itemView.getContext(), Overview.class);
                    intent.putExtra("tt_nocrefnumber", NOCRefernceNumber.getText());
                    itemView.getContext().startActivity(intent);
                }
            });
        }
    }

    public List<TroubleTicketGui> getSwipedTroubleTickets(){
        return swipedTroubleTickets;
    }

    public List<TroubleTicketGui> getItemList() {
        return troubleTicketGuis;
    }
}

0 个答案:

没有答案