I'm having a RecyclerView which has a list of items getting from one API response. I want to show checked state of those recyclerView checkboxes based on another API response i.e in 2nd API response i have some Array of Integers(FacId) shown in image.Based on those Array i want to set the checkboxes state of recyclerView.
public View onCreateView( @NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState ) {
view = inflater.inflate(R.layout.hostel_create_four, container, false);
context = getActivity();
unbinder = ButterKnife.bind(this, view);
btnNext = view.findViewById(R.id.Id_SaveFacilitiesData);
btnPrevious = view.findViewById(R.id.previous);
recyclerView = view.findViewById(R.id.facilitiesRecyclerView);
btnNext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Next();
}
});
btnPrevious.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Previous();
}
});
try {
String check = JocoroApplication.getInstance().getContentType();
if (check.equalsIgnoreCase("Update")){
isUpdate = true;
detailsModel = JocoroApplication.getInstance().getHostelModel();
}
}catch (Exception e){
e.printStackTrace();
}
facilitiesList();
return view;
}
public void Next() {
listener.OnPageChanged(4);
}
public void Previous() {
listener.OnPageChanged(3);
}
public void facilitiesList(){
ApiInterface apiInterface = ApiClient.getClient().create(ApiInterface.class);
Call<Object> call = apiInterface.getHostelFacilities();
ApiRequest.getInstance().serviceCalls(getActivity(), call, new ApiRequest.ServiceCallBack() {
@Override
public void successful(Response response) {
Gson gson = new Gson();
String target = gson.toJson(response.body());
HostelResponseModel responseModel = gson.fromJson(target, HostelResponseModel.class);
if (responseModel.getStatusCode() == 1){
hostelDetailsModelArrayList = responseModel.getData();
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL,false));
adapter = new HostelFacilitiesAdapter(hostelDetailsModelArrayList);
recyclerView.setAdapter(adapter);
}
}
@Override
public void fail(Throwable t) {
}
});
}
public class HostelFacilitiesAdapter extends RecyclerView.Adapter<HostelFacilitiesAdapter.FacilitiesHolder>{
ArrayList<HostelDetailsModel> hostelDetailsModelArrayList;
public HostelFacilitiesAdapter(ArrayList<HostelDetailsModel> hostelDetailsModelArrayList) {
this.hostelDetailsModelArrayList = hostelDetailsModelArrayList;
}
@NonNull
@Override
public FacilitiesHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_hostel_facility, parent, false);
return new FacilitiesHolder(view);
}
@Override
public void onBindViewHolder(@NonNull FacilitiesHolder holder, int position) {
HostelDetailsModel detailsModel = hostelDetailsModelArrayList.get(position);
holder.facilityName.setText(detailsModel.getName());
holder.checkBox.setChecked(detailsModel.isChecked());
}
@Override
public int getItemCount() {
return hostelDetailsModelArrayList.size();
}
public class FacilitiesHolder extends RecyclerView.ViewHolder {
TextView facilityName;
CheckBox checkBox;
public FacilitiesHolder(@NonNull View itemView) {
super(itemView);
facilityName = itemView.findViewById(R.id.tvHostelFacilityName);
checkBox = itemView.findViewById(R.id.cbFacility);
}
Aucun commentaire:
Enregistrer un commentaire