让我稍微解释一下我的问题。在我的回收视图布局中有一个复选框,它在开始时是不可见的。当我点击回收视图中的某个项目时,我希望所有项目中的复选框都可见。我已经在互联网上搜索了很久,但无法找到解决方法。
public class ViewInventoryListAdapter extends RecyclerView.Adapter<ViewInventoryListAdapter.ListViewHolder> {
private Context context;
List<ViewAllInventoryDevicesDetails> list;
private Button assignButton;
private UserLoginResponseModel userLoginResponseModel;
private android.support.v4.app.Fragment fragment;
private FragmentManager fragmentManager;
private FragmentActivity myContext;
private Activity activity;
private int counter = 0;
private List<String> selectedDeviceSerialNumbers;
private static CheckBox checkBox;
public ViewInventoryListAdapter(Context context, List<ViewAllInventoryDevicesDetails> list, Button assign, UserLoginResponseModel model, Activity activity ) {
this.context = context;
this.list = list;
this.assignButton = assign;
this.userLoginResponseModel = model;
this.activity =activity;
}
@NonNull
@Override
public ListViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.view_all_inventory_listlayout_cardview,null);
//Specifying Activity for Fragment Transaction
activity = activity;
myContext = (FragmentActivity) activity;
//Iniallizing Fragment Manager
fragmentManager = myContext.getSupportFragmentManager();
selectedDeviceSerialNumbers = new ArrayList<>();
checkBox = view.findViewById(R.id.view_inventory_checkbox);
return new ViewInventoryListAdapter.ListViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull final ListViewHolder holder, final int position) {
Typeface iconFont = FontManager.getTypeface(context, FontManager.FONTAWESOME);
holder.deviceSerialNumber.setText(list.get(position).getSerialNumber());
holder.deviceType.setText(list.get(position).getDeviceType());
FontManager.markAsIconContainer(holder.deviceIcon, iconFont);
holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
holder.isSelected.setVisibility(View.VISIBLE);
//holder.isSelected.setVisibility(View.VISIBLE);
holder.isSelected.setChecked(true);
assignButton.setVisibility(View.VISIBLE);
return false;
}
});
holder.isSelected.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
holder.isSelected.setChecked(false);
holder.isSelected.setVisibility(View.INVISIBLE);
//Login For Visibility For assign Button
counter--;
selectedDeviceSerialNumbers.remove(list.get(position).getSerialNumber());
if(counter == 0){
assignButton.setVisibility(View.GONE);
}
}
});
assignButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Bundle bundle = new Bundle();
if(userLoginResponseModel != null){
bundle.putSerializable("UserModel", userLoginResponseModel);
bundle.putSerializable("serialNumbers", (Serializable) selectedDeviceSerialNumbers);
}
fragment = new AssingSelectedDevicesFragment();
fragment.setArguments(bundle);
fragmentManager.beginTransaction()
.replace(R.id.flContent, fragment)
.commit();
}
});
}
@Override
public int getItemCount() {
return list.size();
}
class ListViewHolder extends RecyclerView.ViewHolder{
private TextView deviceType, deviceSerialNumber, deviceIcon;
private CheckBox isSelected;
public ListViewHolder(View itemView){
super(itemView);
deviceType = itemView.findViewById(R.id.view_inventory_deviceType_textview);
deviceSerialNumber = itemView.findViewById(R.id.view_inventory_serialNumber_textview);
deviceIcon = itemView.findViewById(R.id.view_inventory_image_textview);
isSelected = itemView.findViewById(R.id.view_inventory_checkbox);
}
}
}
这是我的OnBindViewHolder文本。我可以点击单个项目以改变复选框的可见性。我只想在单击时为所有项目更改。就像我们手机上的联系人列表一样。您只需长按项目,所有项目中都会出现复选框。任何帮助都将不胜感激。 最好的问候