I'm Working on Personal Details model, there have 2 radio option Married and Unmarried.On click of the Married radio button it will enable the Edit Text it will take the Number of Child of that Married person. Based on that entered value for the Edit Text. Dynamically Linear Layout is implementing. But The issues is when click on the Edit Text it's creating the Linear Layout(On erase of the Edit Text the Linear Layout also should erase).
My code is like this. In Main Activity
et_childCount.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if (s != null) {
countI = childCount;
noOfChild = countI;
if (noOfChild >= 1) {
for (int i = 1; i <= noOfChild; i++) {
LinearLayout linearLayout = new LinearLayout(getActivity());
LayoutParams params = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
linearLayout.setLayoutParams(params);
linearLayout.setOrientation(LinearLayout.VERTICAL);
TextView tv_BorderChildDetails = new TextView(getActivity());
tv_BorderChildDetails.setText("Child " + i);
tv_BorderChildDetails.setGravity(Gravity.CENTER_HORIZONTAL);
tv_BorderChildDetails.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
linearLayout.addView(tv_BorderChildDetails);
EditText et_cName = new EditText(getActivity());
EditText et_cDob = new EditText(getActivity());
EditText et_cSchoolName = new EditText(getActivity());
et_cName.setHint("Child name");
et_cDob.setHint("Date of birth");
et_cSchoolName.setHint("School name");
childNameList.add(et_cName);
childDOBList.add(et_cDob);
childSchoolNameList.add(et_cSchoolName);
et_cName.setLayoutParams(params);
et_cDob.setLayoutParams(params);
et_cSchoolName.setLayoutParams(params);
linearLayout.addView(et_cName);
linearLayout.addView(et_cDob);
linearLayout.addView(et_cSchoolName); } } });