📜  带有单选按钮 android 的 recyclerview - 任何代码示例

📅  最后修改于: 2022-03-11 14:56:13.790000             🧑  作者: Mango

代码示例1
public class ViewHolder extends RecyclerView.ViewHolder {

     @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        boolean ischecked = position == checkedposition ? true : false;

        holder.tv.setText(productList.get(position));
        holder.tv.setChecked(lastSelectedPosition == position);
         selectionState.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    lastSelectedPosition = getAdapterPosition();
                    notifyDataSetChanged();

                    Toast.makeText(OffersRecyclerViewAdapter.this.context,
                            "selected offer is " + offerName.getText(),
                                        Toast.LENGTH_LONG).show();
                }
            });
    }