本文介绍了如何使单个视图支架不可回收的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只希望使一个视图回收器不可回收,而不是整个视图回收器.我该怎么办?我不希望btnSave可回收,因为每行的状态都可能不同.

I want to make only one item of the viewholder non recyclable and not the whole viewholder. How can I do so?I dont want the btnSave to be recyclable since its state may be different for each row.

这是我到目前为止所做的代码:

Here is the code of what I have done so far :

public static class AlertViewHolder extends RecyclerView.ViewHolder {
    TextView tvTitle, tvDescription;
    Button btnLink, btnSave;

    AlertViewHolder(View itemView) {
        super(itemView);
        tvTitle = (TextView) itemView.findViewById(R.id.tvTitle);
        tvDescription = (TextView) itemView.findViewById(R.id.tvDescription);
        btnLink = (Button) itemView.findViewById(R.id.btnLink);
        btnSave = (Button) itemView.findViewById(R.id.btnSave);

        btnLink.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(alerts.get(getAdapterposition()).getLink()));
            context.startActivity(browserIntent);
        }
    });

        btnSave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onSaveClicked(view);
            }
        });

     this.setIsRecyclable(false);
    }

    void onSaveClicked(View view) {
        DbHelper.getInstance(context).addSavedFeedRecord(alerts.get(getAdapterPosition()));
        Snackbar.make(view, "Item Saved", Snackbar.LENGTH_LONG)
                .setAction("UNDO", null).show();
        view.setEnabled(false);
    }
}

或另一种方式是:

@Override
public void onBindViewHolder(AlertViewHolder alertViewHolder, final int i) {
    alertViewHolder.setIsRecyclable(false);
    alertViewHolder.tvDescription.setText(alerts.get(i).getDesc());

}

推荐答案

您可以包装

这篇关于如何使单个视图支架不可回收的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 12:16