value of dynamically created editext not getting stored

Hi i have been working on an app where i have a plus button and onclick of that plus button i'm inflating a layout. Every time user clicks on plus button a new layout is created now i'm adding the data from editext to database and so far every thing is working however my problem is that only last editext value is getting stored in database i have two editext in layout and i'm using retrofit for api call. So please if someone could help me here

**Edit:debugged the code and maintained a separate arraylist and it returns the proper size however when i use a for loop for sending data as you can see in the second piece of code only last data is getting repeated **

Here is the method to inflate the layout

 public void makedifferentEditText() {
        try {

                View secondchild = getLayoutInflater().inflate(R.layout.update_extra_links_layout, null);
                final LinearLayout update_extra_links_layout = (LinearLayout) secondchild.findViewById(R.id.update_extra_links_layout);
                customtextTitle = (CustomEditTextThin) secondchild.findViewById(R.id.google_edit_link);
                customeditTextLink = (CustomEditTextThin) secondchild.findViewById(R.id.facebook_edit_link);
                google_tilte.add(customtextTitle);
                google_link.add(customeditTextLink);
                Log.e("title",google_tilte.toString());
                Log.e("link",google_link.toString());
                //String customLink = customeditTextLink.getText().toString();
                AppCompatImageView removeimage = (AppCompatImageView) secondchild.findViewById(R.id.icon_remove_link);
                //arrayLink.add(customLink);
                //arrayLink.add(customtextTitle.getText().toString());

//            for(int i=0;i<200;i++){
//                customLink[i] = customeditTextLink.getText().toString();
//                customGoogleLink[i] = customeditTextLink.getText().toString();
//            }
                eexId = (TextView) secondchild.findViewById(R.id.eeid);

                rAlign.addView(update_extra_links_layout);
                removeimage.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        rAlign.removeView(update_extra_links_layout);
                    }
                });

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

and Here is how i'm getting the data to send

if(google_link!=null && google_link.size()>0) {
                    for(int j=0;j<google_link.size();j++) {
                        arrayTitle.add(google_link.get(j).getText().toString());
                        Log.e("array", arrayTitle.toString());
                            if (customtextTitle != null && customeditTextLink != null) {
                                if (arrayTitle != null) {
                                    for (String link : arrayTitle) {
                                        ExtraLinksObject links4 = new ExtraLinksObject();
                                        String othergoogleTitle = customtextTitle.getText().toString();
                                        String othergooglelink = link;//customeditTextLink.getText().toString();
                                        String googleId = eexId.getText().toString();
                                        links4.setLink(othergooglelink);
                                        links4.setTitle(othergoogleTitle);
                                        links4.setExID(googleId);

                                        extraLinks.add(links4);
                                    }
                                }
                            }
                        }
                    }

1 answer

  • answered 2018-07-11 06:58 Vinay Rathod

    you can get one by one child for view and add to DB

    for(int i = 0; i < rAlign.getChildCount();i++) {
        View secondchild = rAlign.getChildAt(i);
        customtextTitle = (CustomEditTextThin) secondchild.findViewById(R.id.google_edit_link);
        customeditTextLink = (CustomEditTextThin) secondchild.findViewById(R.id.facebook_edit_link);
        eexId = (TextView) secondchild.findViewById(R.id.eeid);
        if (customtextTitle != null && customeditTextLink != null) {
            ExtraLinksObject links4 = new ExtraLinksObject();
            String othergoogleTitle = customtextTitle.getText().toString();
            String othergooglelink = customeditTextLink.getText().toString();
            String googleId = eexId.getText().toString();
            links4.setLink(othergooglelink);
            links4.setTitle(othergoogleTitle);
            links4.setExID(googleId);
            extraLinks.add(links4);
        }
    }