Я показываю форму в RecyclerView
. Форма имеет editText, щелкнув по нему, я открываю datepickerDialog, чтобы пользователь мог выбрать дату и установить на editText. Итак, моя проблема в том, что когда я нажимаю на editText в 3-й позиции и выбираю дату, дата устанавливается в форму в 1-й позиции. Ниже приведен класс адаптера
public class ClaimAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements ClaimAdapterCallback {
RelativeLayout parentLayout;
Context context;
public ArrayList<SubmitClaimModel> claimList;
private static final int TYPE_FOOTER = 1;
private static final int TYPE_ITEM = 2;
private static final int TYPE_HEADER = 0;
public ClaimAdapter(Context context, ArrayList<SubmitClaimModel> claimList, RelativeLayout parentLayout, String language, String token){
this.context = context;
this.claimList = claimList;
alertDialogs = new AlertDialogs();
this.parentLayout = parentLayout;
this.language = language;
this.token = token;
databaseHelper = new DatabaseHelper(context);
alertConfig = new AlertConfig();
alertConfig.custommbDialog((Activity) context);
claimAdapterCallback = this;
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
if (viewType == TYPE_ITEM) {
View itemView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.claim_adapter, viewGroup, false);
return new ClaimViewHolder(itemView);
} else if (viewType == TYPE_FOOTER) {
//Inflating footer view
View itemView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.submit_claim_footer, viewGroup, false);
return new FooterViewHolder(itemView);
}
else if(viewType == TYPE_HEADER){
View itemView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.submit_claim_header, viewGroup, false);
return new HeaderViewHolder(itemView);
}
else return null;
}
@Override
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, final int i) {
holder.setIsRecyclable(false);
if (holder instanceof ClaimViewHolder) {
submitClaimModel = null;
submitClaimModel = claimList.get(holder.getAdapterPosition()-1);
claimViewHolder = (ClaimViewHolder) holder;
Log.e(holder.getAdapterPosition()-1+"", submitClaimModel.getAmount());
claimViewHolder.spinner_selectProvider.requestLayout();
//int count = (holder.getAdapterPosition()-1)+1;
claimViewHolder.tv_invoiceName.setText("Invoice "+holder.getAdapterPosition());
updateViewsAsPerData(submitClaimModel);
claimViewHolder.rl_button_del1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
claimList.remove(holder.getAdapterPosition()-1);
notifyDataSetChanged();
}
});
final Calendar myCalendar = Calendar.getInstance();
final DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
myCalendar.set(Calendar.YEAR, year);
myCalendar.set(Calendar.MONTH, monthOfYear);
myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
updateLabel(submitClaimModel, myCalendar, holder.getAdapterPosition()-1, claimViewHolder);
}
};
claimViewHolder.et_dos.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Locale locale = context.getResources().getConfiguration().locale;
Locale.setDefault(locale);
DatePickerDialog dialog = new DatePickerDialog(context, date, myCalendar
.get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
myCalendar.get(Calendar.DAY_OF_MONTH));
dialog.setButton(DatePickerDialog.BUTTON_POSITIVE, context.getResources().getString(R.string.Ok), dialog);
dialog.setButton(DatePickerDialog.BUTTON_NEGATIVE, context.getResources().getString(R.string.cancel), dialog);
dialog.show();
}
});
claimViewHolder.card_view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
((SubmitClaimDynamic)context).startDialog(context, claimAdapterCallback, invoiceImageType, context.getResources().getString(R.string.upload),
context.getResources().getString(R.string.howupload));
}
});
claimViewHolder.imgv_close_upload.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
claimViewHolder.imgv_logo.setImageResource(R.drawable.ic_uploadinvoice);
claimViewHolder.imgv_logo.setVisibility(View.VISIBLE);
claimViewHolder.imgv_invoice_pic.setVisibility(View.GONE);
Snackbar.make(v, context.getResources().getString(R.string.uploadedfile),3000).show();
claimViewHolder.imgv_close_upload.setVisibility(View.GONE);
submitClaimModel.setInvoiceImage("");
}
});
claimViewHolder.card_view_medical_description.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
((SubmitClaimDynamic)context).startDialog(context, claimAdapterCallback, medicalPrescription, context.getResources().getString(R.string.uploadmd),
context.getResources().getString(R.string.howuploadmd));
}
});
claimViewHolder.imgv_close_upload_medical_description.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
claimViewHolder.imgv_logo_medical_description.setImageResource(R.drawable.ic_uploadinvoice);
claimViewHolder.imgv_logo_medical_description.setVisibility(View.VISIBLE);
claimViewHolder.imgv_invoice_pic_medical_description.setVisibility(View.GONE);
Snackbar.make(v, context.getString(R.string.uploadedfile),3000).show();
claimViewHolder.imgv_close_upload_medical_description.setVisibility(View.GONE);
submitClaimModel.setMedicalDescriptionImage("");
}
});
claimViewHolder.card_view_medical_report.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
((SubmitClaimDynamic)context).startDialog(context, claimAdapterCallback, medicalReport, context.getResources().getString(R.string.uploadmrp),
context.getResources().getString(R.string.howuploadmrp));
}
});
claimViewHolder.imgv_close_upload_medical_report.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
claimViewHolder.imgv_logo_medical_report.setImageResource(R.drawable.ic_uploadinvoice);
claimViewHolder.imgv_logo_medical_report.setVisibility(View.VISIBLE);
claimViewHolder.imgv_invoice_pic_medical_report.setVisibility(View.GONE);
Snackbar.make(v, context.getString(R.string.uploadedfile),3000).show();
claimViewHolder.imgv_close_upload_medical_report.setVisibility(View.GONE);
submitClaimModel.setMedicalReportImage("");
}
});
}
else if (holder instanceof FooterViewHolder)
{
FooterViewHolder footerHolder = (FooterViewHolder) holder;
footerHolder.selectRIM.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if(b)
isTermsAccepted = true;
else
isTermsAccepted = false;
}
});
footerHolder.et_comment.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
comment = editable.toString();
}
});
}
}
@Override
public int getItemViewType(int position) {
if (position == 0) {
return TYPE_HEADER;
}
else if (position == claimList.size()+1) {
return TYPE_FOOTER;
}
return TYPE_ITEM;
}
@Override
public int getItemCount() {
return claimList.size()+2;
}
public void addForm(SubmitClaimModel model){
claimList.add(model);
notifyDataSetChanged();
}
private void updateLabel(SubmitClaimModel submitClaimModel, Calendar myCalendar, int position, ClaimViewHolder holder) {
String myFormat = "MM-dd-yyyy"; //In which you need put here
SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.US);
holder.et_dos.setText(sdf.format(myCalendar.getTime()));
//submitClaimModel.setDateOfTreatment(holder.et_dos.getText().toString());
claimList.get(position).setDateOfTreatment(holder.et_dos.getText().toString());
claimViewHolder.spinner_selectbenifits.setEnabled(true);
notifyItemChanged(position+1);
ApiManager apiManager = new ApiManager(context, language, token, this);
apiManager.getBenefit(submitClaimModel.getPatientId(), holder.et_dos.getText().toString());
}
public void addBeneficiarySpinnerData(ArrayList<String> arrayListBen, ArrayList<String> arrayListBenID){
this.arrayListBen.addAll(arrayListBen);
this.arrayListBenID.addAll(arrayListBenID);
notifyDataSetChanged();
}
public void addCountrySpinnerData(ArrayList<String> arrayListCountries, ArrayList<String> arrayListCountriesID){
this.arrayListCountries.addAll(arrayListCountries);
this.arrayListCountriesID.addAll(arrayListCountriesID);
notifyDataSetChanged();
}
public void addCurrencySpinnerData(ArrayList<String> arrayListCurrencies){
this.arrayListCurrencies = arrayListCurrencies;
notifyDataSetChanged();
}
public void addMedicalProcedureSpinnerData(ArrayList<String> arrayListMedicalProcedures, ArrayList<String> arrayListMedicalProceduresID){
this.arrayListMedicalProcedures.addAll(arrayListMedicalProcedures);
this.arrayListMedicalProceduresID.addAll(arrayListMedicalProceduresID);
notifyDataSetChanged();
}
public void addSpecialitiesSpinnerData(ArrayList<String> arrayListSpecialities, ArrayList<String> arrayListSpecialitiesID){
this.arrayListSpecialities.addAll(arrayListSpecialities);
this.arrayListSpecialitiesID.addAll(arrayListSpecialitiesID);
notifyDataSetChanged();
}
@Override
public void parseBenefitsResonse(String response) {
arrayListBenefit.clear();
try {
JSONObject jsonObject = new JSONObject(response);
int ResponseCode = jsonObject.getInt("ResponseCode");
if(ResponseCode == 200){
JSONArray jsonArray = jsonObject.getJSONArray("Benefits");
for(int i=0;i<jsonArray.length();i++){
JSONObject jsonObjectBenefit = jsonArray.getJSONObject(i);
int Id = jsonObjectBenefit.getInt("Id");
String Name = jsonObjectBenefit.getString("Name");
databaseHelper.insertaAllBenefitDetails(Name,String.valueOf(Id),"Claim");
arrayListBenefit.add(Name);
}
claimViewHolder.spinner_selectbenifits.setItems(arrayListBenefit);
//notifyDataSetChanged();
}else if(ResponseCode==401){
alertConfig.callDialog((Activity) context, "com.expat.expa.UIClasses.LoginActivity");
}
} catch (JSONException e) {
e.printStackTrace();
Log.e("Benefit Exception",e.getMessage().toString());
}
}
@Override
public void getSelectedImage(String imageType, String imageBase64, Bitmap bitmap) {
if(imageType.equalsIgnoreCase(invoiceImageType)){
claimViewHolder.imgv_close_upload.setVisibility(View.VISIBLE);
claimViewHolder.imgv_invoice_pic.setVisibility(View.VISIBLE);
claimViewHolder.imgv_invoice_pic.setImageDrawable(null);
claimViewHolder.imgv_invoice_pic.setImageBitmap(bitmap);
claimViewHolder.imgv_logo.setVisibility(View.GONE);
submitClaimModel.setInvoiceImage(imageBase64);
submitClaimModel.setInvoiceBitmap(bitmap);
}
else if(imageType.equalsIgnoreCase(medicalPrescription)){
claimViewHolder.imgv_close_upload_medical_description.setVisibility(View.VISIBLE);
claimViewHolder.imgv_invoice_pic_medical_description.setVisibility(View.VISIBLE);
claimViewHolder.imgv_invoice_pic_medical_description.setImageDrawable(null);
claimViewHolder.imgv_invoice_pic_medical_description.setImageBitmap(bitmap);
claimViewHolder.imgv_logo_medical_description.setVisibility(View.GONE);
submitClaimModel.setMedicalDescriptionImage(imageBase64);
submitClaimModel.setMedicalDescriptionBitmap(bitmap);
}
else if(imageType.equalsIgnoreCase(medicalReport)){
claimViewHolder.imgv_invoice_pic_medical_report.setVisibility(View.VISIBLE);
claimViewHolder.imgv_invoice_pic_medical_report.setImageDrawable(null);
claimViewHolder.imgv_invoice_pic_medical_report.setImageBitmap(bitmap);
claimViewHolder.imgv_close_upload_medical_report.setVisibility(View.VISIBLE);
claimViewHolder.imgv_logo_medical_report.setVisibility(View.GONE);
submitClaimModel.setMedicalReportImage(imageBase64);
submitClaimModel.setMedicalReportBitmal(bitmap);
}
}
@Override
public long getItemId(int position) {
return position;
}
class ClaimViewHolder extends RecyclerView.ViewHolder{
LinearLayout ll_form;
//Spinner spinner_selectProvider;
MaterialSpinner spinner_selectbenifits, spinner_visitreason, spinner_medicalprocedure, et_country_name, et_hospitalname,
spinner_doctorspeciality, et_nhs_currency, et_currency, spinner_selectProvider;
EditText et_dos, et_amount, et_city_name, et_hospitalname_other, et_nameofdrugs, et_nameofdrugs_other, et_doctorname, et_doctorname_other, et_speciality_other,
et_gop_number, et_national_health_scheme, et_diagnosis_other, et_medical_procedure_other;
RelativeLayout rl_imgv_lay, rl_bttn, rl_bttn_medical_description, rl_bttn_medical_report, rl_button_edit1, rl_button_del1;
ImageView imgv_logo, imgv_invoice_pic, imgv_close_upload, imgv_logo_medical_description, imgv_invoice_pic_medical_description, imgv_close_upload_medical_description,
imgv_logo_medical_report, imgv_invoice_pic_medical_report, imgv_close_upload_medical_report;
FontTextViewOpensSansRegular tv_invoiceName;
CardView card_view_medical_report, card_view_medical_description, card_view;
public ClaimViewHolder(@NonNull View itemView) {
super(itemView);
//et_hospitalname.setEnabled(false);
et_dos.setFocusable(false);
rl_button_edit1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(ll_form.getVisibility() == View.GONE)
ll_form.setVisibility(View.VISIBLE);
else
ll_form.setVisibility(View.GONE);
}
});
et_hospitalname.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction()==MotionEvent.ACTION_UP){
alertDialogs.openPopUpHospital((Activity) context,"one", parentLayout, context, et_hospitalname, et_hospitalname_other, claimAdapterCallback);
return true;
}
return false;
}
});
spinner_medicalprocedure.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction()==MotionEvent.ACTION_UP){
alertDialogs.openPopUpMP((Activity) context,"one", parentLayout,context, spinner_medicalprocedure, et_medical_procedure_other, claimAdapterCallback);
return true;
}
return false;
}
});
spinner_visitreason.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction()==MotionEvent.ACTION_UP){
alertDialogs.openPopUpReason((Activity) context,"one", parentLayout, context, spinner_visitreason, et_diagnosis_other, claimAdapterCallback);
return true;
}
return false;
}
});
}
}
class FooterViewHolder extends RecyclerView.ViewHolder{
EditText et_comment;
CheckBox selectRIM;
public FooterViewHolder(@NonNull View itemView) {
super(itemView);
et_comment = itemView.findViewById(R.id.et_comment);
selectRIM = itemView.findViewById(R.id.selectRIM);
}
}
class HeaderViewHolder extends RecyclerView.ViewHolder{
public HeaderViewHolder(@NonNull View itemView) {
super(itemView);
}
}
class CustomTextWatcher implements TextWatcher {
SubmitClaimModel submitClaimModel;
EditText editText;
MaterialSpinner materialSpinner;
CustomTextWatcher(SubmitClaimModel submitClaimModel, EditText editText){
this.submitClaimModel = submitClaimModel;
this.editText = editText;
}
CustomTextWatcher(SubmitClaimModel submitClaimModel, MaterialSpinner materialSpinner){
this.submitClaimModel = submitClaimModel;
this.materialSpinner = materialSpinner;
}
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
if(editText != null){
switch (editText.getId()){
case R.id.et_doctorname:
submitClaimModel.setDoctorName(editable.toString());
break;
case R.id.et_amount:
submitClaimModel.setAmount(editable.toString());
break;
case R.id.et_city_name:
submitClaimModel.setCityName(editable.toString());
break;
case R.id.et_nameofdrugs:
submitClaimModel.setDrugName(editable.toString());
break;
case R.id.et_hospitalname_other:
submitClaimModel.setHospitalNameOthers(editable.toString());
break;
case R.id.et_medical_procedure_other:
submitClaimModel.setMedicalProcedureOther(editable.toString());
break;
case R.id.et_diagnosis_other:
submitClaimModel.setReasonOther(editable.toString());
break;
case R.id.et_national_health_scheme:
submitClaimModel.setNationalScheme(editable.toString());
break;
case R.id.et_speciality_other:
submitClaimModel.setDoctorSpecialityOther(editable.toString());
break;
}
}else{
switch (materialSpinner.getId()){
case R.id.et_hospitalname:
submitClaimModel.setHospitalName(editable.toString());
break;
case R.id.spinner_medicalprocedure:
submitClaimModel.setMedicalProcedure(editable.toString());
break;
case R.id.spinner_visitreason:
submitClaimModel.setReason(editable.toString());
break;
}
}
}
}
@Override
public void getSelectedReason(String reason, String reasonId) {
if(submitClaimModel != null){
ClaimAdapter.submitClaimModel.setReasonId(reasonId);
submitClaimModel.setReason(reason);
}
}
@Override
public void getMedicalProcedure(String name, String id) {
if(submitClaimModel != null) {
submitClaimModel.setMedicalProcedureId(id);
submitClaimModel.setMedicalProcedure(name);
}
}
@Override
public void getHospital(String name, String id) {
if(submitClaimModel != null) {
submitClaimModel.setHospitalId(id);
submitClaimModel.setHospitalName(name);
}
}
@Override
public void updateDate(String date, SubmitClaimModel submitClaimModel) {
claimViewHolder.et_dos.setText(date);
submitClaimModel.setDateOfTreatment(date);
claimViewHolder.spinner_selectbenifits.setEnabled(true);
ApiManager apiManager = new ApiManager(context, language, token, this);
apiManager.getBenefit(submitClaimModel.getPatientId(), date);
}
}
}
et_dos - мой текст редактирования, который открывает datePickerDialog.