EditText takes only last value in dynamic form












0















I have created a dynamic form. The field in the form is created in respect to the field type set in the backend. All the data of the dynamically created editText is set in arrayList. There is no problem for type "String" but in case of date, a problem occurs. The problem is that if there are 2 date fields, the value of the last datefield is set even if i chose and set the date field of first date field. The code can be seen below:



 call.enqueue(new Callback<SifarisMainModel>() {
@Override
public void onResponse(Call<SifarisMainModel> call, retrofit2.Response<SifarisMainModel> response) {
String url = call.request().toString();
Log.e("urlChoseSifaris",url.toString() + "");

for(FieldArray fieldArray: response.body().getFiledArray()){
counter++;
name = fieldArray.getNepaliName();
fieldType = fieldArray.getFieldType();
keyList.add(fieldArray.getName());
getForm();

}
}

@Override
public void onFailure(Call<SifarisMainModel> call, Throwable t) {

}
});



public void getForm(){
case "DATE":
et = new EditText(this);
list.add(et);
et.setInputType(InputType.TYPE_CLASS_DATETIME);
et.setTextColor(getResources().getColor(R.color.black));
sifarisMainlayout.addView(et);
et.setFocusable(false);
et.setCursorVisible(false);
et.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);

DatePickerDialog datePickerDialog = new DatePickerDialog(ChooseSifaris.this,
new DatePickerDialog.OnDateSetListener() {

@Override
public void onDateSet(android.widget.DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
et.setText(dayOfMonth + "-" + (monthOfYear + 1) + "-" + year);

}
}, mYear, mMonth, mDay);
datePickerDialog.show();
}
});
break;

}









share|improve this question























  • it could be because the clicklistner for date picker is set on the last date form, it's not clear from this code snippet though.

    – NIKHIL MAURYA
    Nov 19 '18 at 9:19











  • @NIKHILMAURYA yes it is taking only last date form.

    – Sudeep
    Nov 19 '18 at 11:08











  • move list.add(et) after the assignment of clicklistner

    – NIKHIL MAURYA
    Nov 19 '18 at 11:10











  • @NIKHILMAURYA it is still not working bro. same prob. the value of last form with date changes

    – Sudeep
    Nov 19 '18 at 11:59











  • Add one more line EditText et = new EditText(this); instead of et = new EditText(this); I don't think this would work either but let's try it.

    – NIKHIL MAURYA
    Nov 19 '18 at 12:14


















0















I have created a dynamic form. The field in the form is created in respect to the field type set in the backend. All the data of the dynamically created editText is set in arrayList. There is no problem for type "String" but in case of date, a problem occurs. The problem is that if there are 2 date fields, the value of the last datefield is set even if i chose and set the date field of first date field. The code can be seen below:



 call.enqueue(new Callback<SifarisMainModel>() {
@Override
public void onResponse(Call<SifarisMainModel> call, retrofit2.Response<SifarisMainModel> response) {
String url = call.request().toString();
Log.e("urlChoseSifaris",url.toString() + "");

for(FieldArray fieldArray: response.body().getFiledArray()){
counter++;
name = fieldArray.getNepaliName();
fieldType = fieldArray.getFieldType();
keyList.add(fieldArray.getName());
getForm();

}
}

@Override
public void onFailure(Call<SifarisMainModel> call, Throwable t) {

}
});



public void getForm(){
case "DATE":
et = new EditText(this);
list.add(et);
et.setInputType(InputType.TYPE_CLASS_DATETIME);
et.setTextColor(getResources().getColor(R.color.black));
sifarisMainlayout.addView(et);
et.setFocusable(false);
et.setCursorVisible(false);
et.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);

DatePickerDialog datePickerDialog = new DatePickerDialog(ChooseSifaris.this,
new DatePickerDialog.OnDateSetListener() {

@Override
public void onDateSet(android.widget.DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
et.setText(dayOfMonth + "-" + (monthOfYear + 1) + "-" + year);

}
}, mYear, mMonth, mDay);
datePickerDialog.show();
}
});
break;

}









share|improve this question























  • it could be because the clicklistner for date picker is set on the last date form, it's not clear from this code snippet though.

    – NIKHIL MAURYA
    Nov 19 '18 at 9:19











  • @NIKHILMAURYA yes it is taking only last date form.

    – Sudeep
    Nov 19 '18 at 11:08











  • move list.add(et) after the assignment of clicklistner

    – NIKHIL MAURYA
    Nov 19 '18 at 11:10











  • @NIKHILMAURYA it is still not working bro. same prob. the value of last form with date changes

    – Sudeep
    Nov 19 '18 at 11:59











  • Add one more line EditText et = new EditText(this); instead of et = new EditText(this); I don't think this would work either but let's try it.

    – NIKHIL MAURYA
    Nov 19 '18 at 12:14
















0












0








0


0






I have created a dynamic form. The field in the form is created in respect to the field type set in the backend. All the data of the dynamically created editText is set in arrayList. There is no problem for type "String" but in case of date, a problem occurs. The problem is that if there are 2 date fields, the value of the last datefield is set even if i chose and set the date field of first date field. The code can be seen below:



 call.enqueue(new Callback<SifarisMainModel>() {
@Override
public void onResponse(Call<SifarisMainModel> call, retrofit2.Response<SifarisMainModel> response) {
String url = call.request().toString();
Log.e("urlChoseSifaris",url.toString() + "");

for(FieldArray fieldArray: response.body().getFiledArray()){
counter++;
name = fieldArray.getNepaliName();
fieldType = fieldArray.getFieldType();
keyList.add(fieldArray.getName());
getForm();

}
}

@Override
public void onFailure(Call<SifarisMainModel> call, Throwable t) {

}
});



public void getForm(){
case "DATE":
et = new EditText(this);
list.add(et);
et.setInputType(InputType.TYPE_CLASS_DATETIME);
et.setTextColor(getResources().getColor(R.color.black));
sifarisMainlayout.addView(et);
et.setFocusable(false);
et.setCursorVisible(false);
et.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);

DatePickerDialog datePickerDialog = new DatePickerDialog(ChooseSifaris.this,
new DatePickerDialog.OnDateSetListener() {

@Override
public void onDateSet(android.widget.DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
et.setText(dayOfMonth + "-" + (monthOfYear + 1) + "-" + year);

}
}, mYear, mMonth, mDay);
datePickerDialog.show();
}
});
break;

}









share|improve this question














I have created a dynamic form. The field in the form is created in respect to the field type set in the backend. All the data of the dynamically created editText is set in arrayList. There is no problem for type "String" but in case of date, a problem occurs. The problem is that if there are 2 date fields, the value of the last datefield is set even if i chose and set the date field of first date field. The code can be seen below:



 call.enqueue(new Callback<SifarisMainModel>() {
@Override
public void onResponse(Call<SifarisMainModel> call, retrofit2.Response<SifarisMainModel> response) {
String url = call.request().toString();
Log.e("urlChoseSifaris",url.toString() + "");

for(FieldArray fieldArray: response.body().getFiledArray()){
counter++;
name = fieldArray.getNepaliName();
fieldType = fieldArray.getFieldType();
keyList.add(fieldArray.getName());
getForm();

}
}

@Override
public void onFailure(Call<SifarisMainModel> call, Throwable t) {

}
});



public void getForm(){
case "DATE":
et = new EditText(this);
list.add(et);
et.setInputType(InputType.TYPE_CLASS_DATETIME);
et.setTextColor(getResources().getColor(R.color.black));
sifarisMainlayout.addView(et);
et.setFocusable(false);
et.setCursorVisible(false);
et.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);

DatePickerDialog datePickerDialog = new DatePickerDialog(ChooseSifaris.this,
new DatePickerDialog.OnDateSetListener() {

@Override
public void onDateSet(android.widget.DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
et.setText(dayOfMonth + "-" + (monthOfYear + 1) + "-" + year);

}
}, mYear, mMonth, mDay);
datePickerDialog.show();
}
});
break;

}






android datepicker retrofit2 dynamicform






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 '18 at 9:00









SudeepSudeep

125




125













  • it could be because the clicklistner for date picker is set on the last date form, it's not clear from this code snippet though.

    – NIKHIL MAURYA
    Nov 19 '18 at 9:19











  • @NIKHILMAURYA yes it is taking only last date form.

    – Sudeep
    Nov 19 '18 at 11:08











  • move list.add(et) after the assignment of clicklistner

    – NIKHIL MAURYA
    Nov 19 '18 at 11:10











  • @NIKHILMAURYA it is still not working bro. same prob. the value of last form with date changes

    – Sudeep
    Nov 19 '18 at 11:59











  • Add one more line EditText et = new EditText(this); instead of et = new EditText(this); I don't think this would work either but let's try it.

    – NIKHIL MAURYA
    Nov 19 '18 at 12:14





















  • it could be because the clicklistner for date picker is set on the last date form, it's not clear from this code snippet though.

    – NIKHIL MAURYA
    Nov 19 '18 at 9:19











  • @NIKHILMAURYA yes it is taking only last date form.

    – Sudeep
    Nov 19 '18 at 11:08











  • move list.add(et) after the assignment of clicklistner

    – NIKHIL MAURYA
    Nov 19 '18 at 11:10











  • @NIKHILMAURYA it is still not working bro. same prob. the value of last form with date changes

    – Sudeep
    Nov 19 '18 at 11:59











  • Add one more line EditText et = new EditText(this); instead of et = new EditText(this); I don't think this would work either but let's try it.

    – NIKHIL MAURYA
    Nov 19 '18 at 12:14



















it could be because the clicklistner for date picker is set on the last date form, it's not clear from this code snippet though.

– NIKHIL MAURYA
Nov 19 '18 at 9:19





it could be because the clicklistner for date picker is set on the last date form, it's not clear from this code snippet though.

– NIKHIL MAURYA
Nov 19 '18 at 9:19













@NIKHILMAURYA yes it is taking only last date form.

– Sudeep
Nov 19 '18 at 11:08





@NIKHILMAURYA yes it is taking only last date form.

– Sudeep
Nov 19 '18 at 11:08













move list.add(et) after the assignment of clicklistner

– NIKHIL MAURYA
Nov 19 '18 at 11:10





move list.add(et) after the assignment of clicklistner

– NIKHIL MAURYA
Nov 19 '18 at 11:10













@NIKHILMAURYA it is still not working bro. same prob. the value of last form with date changes

– Sudeep
Nov 19 '18 at 11:59





@NIKHILMAURYA it is still not working bro. same prob. the value of last form with date changes

– Sudeep
Nov 19 '18 at 11:59













Add one more line EditText et = new EditText(this); instead of et = new EditText(this); I don't think this would work either but let's try it.

– NIKHIL MAURYA
Nov 19 '18 at 12:14







Add one more line EditText et = new EditText(this); instead of et = new EditText(this); I don't think this would work either but let's try it.

– NIKHIL MAURYA
Nov 19 '18 at 12:14














0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371241%2fedittext-takes-only-last-value-in-dynamic-form%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371241%2fedittext-takes-only-last-value-in-dynamic-form%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Can I use Tabulator js library in my java Spring + Thymeleaf project?