How to get text from all EditText Dynamically added in a row












-1














The EditText is Dynamically added by user .
how get data from each dynamically created EditText .or get values from the dynamically created EditTexts when the user tap a save button, then store all of them , dynamically added by user and save as Share preferences or save as array thanks guys



public class ActivityOptions extends AppCompatActivity {
private LinearLayout parentLinearLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_options);
parentLinearLayout = (LinearLayout) findViewById(R.id.parent_linear_layout);

}
public void onAddField(View v) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View rowView = inflater.inflate(R.layout.field, null);
// Add the new row before the add field button.
parentLinearLayout.addView(rowView, parentLinearLayout.getChildCount() - 1);
}

public void onDelete(View v) {
parentLinearLayout.removeView((View) v.getParent());
}


activity.xml



 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/parent_linear_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:orientation="vertical" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal" >
<EditText
android:id="@+id/edit_text"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="5"
android:inputType="text"/>
<Button
android:id="@+id/delete_button"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="1"
android:background="@android:drawable/ic_delete"
android:onClick="onDelete"/>
</LinearLayout>
<Button
android:id="@+id/add_field_button"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="#555"
android:layout_gravity="center"
android:onClick="onAddField"
android:textColor="#FFF"
android:text="Add Field"
android:paddingLeft="5dp"/>
<TextView
android:layout_marginTop="10dp"
android:gravity="center"
android:id="@+id/txt"
android:text="HELLO"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>


fiel.xml



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal" >
<EditText
android:id="@+id/edit_text"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="5"
android:inputType="text"/>
<Button
android:id="@+id/delete_button"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="1"
android:background="@android:drawable/ic_delete"
android:onClick="onDelete"/>
</LinearLayout>









share|improve this question
























  • Your code doesn't have any EditText related code. Only post code that is relevant to the question.
    – Lekr0
    Nov 23 '18 at 13:55










  • the EditText is Dynamically Added !
    – Droid Projects
    Nov 23 '18 at 14:33


















-1














The EditText is Dynamically added by user .
how get data from each dynamically created EditText .or get values from the dynamically created EditTexts when the user tap a save button, then store all of them , dynamically added by user and save as Share preferences or save as array thanks guys



public class ActivityOptions extends AppCompatActivity {
private LinearLayout parentLinearLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_options);
parentLinearLayout = (LinearLayout) findViewById(R.id.parent_linear_layout);

}
public void onAddField(View v) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View rowView = inflater.inflate(R.layout.field, null);
// Add the new row before the add field button.
parentLinearLayout.addView(rowView, parentLinearLayout.getChildCount() - 1);
}

public void onDelete(View v) {
parentLinearLayout.removeView((View) v.getParent());
}


activity.xml



 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/parent_linear_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:orientation="vertical" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal" >
<EditText
android:id="@+id/edit_text"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="5"
android:inputType="text"/>
<Button
android:id="@+id/delete_button"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="1"
android:background="@android:drawable/ic_delete"
android:onClick="onDelete"/>
</LinearLayout>
<Button
android:id="@+id/add_field_button"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="#555"
android:layout_gravity="center"
android:onClick="onAddField"
android:textColor="#FFF"
android:text="Add Field"
android:paddingLeft="5dp"/>
<TextView
android:layout_marginTop="10dp"
android:gravity="center"
android:id="@+id/txt"
android:text="HELLO"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>


fiel.xml



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal" >
<EditText
android:id="@+id/edit_text"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="5"
android:inputType="text"/>
<Button
android:id="@+id/delete_button"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="1"
android:background="@android:drawable/ic_delete"
android:onClick="onDelete"/>
</LinearLayout>









share|improve this question
























  • Your code doesn't have any EditText related code. Only post code that is relevant to the question.
    – Lekr0
    Nov 23 '18 at 13:55










  • the EditText is Dynamically Added !
    – Droid Projects
    Nov 23 '18 at 14:33
















-1












-1








-1







The EditText is Dynamically added by user .
how get data from each dynamically created EditText .or get values from the dynamically created EditTexts when the user tap a save button, then store all of them , dynamically added by user and save as Share preferences or save as array thanks guys



public class ActivityOptions extends AppCompatActivity {
private LinearLayout parentLinearLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_options);
parentLinearLayout = (LinearLayout) findViewById(R.id.parent_linear_layout);

}
public void onAddField(View v) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View rowView = inflater.inflate(R.layout.field, null);
// Add the new row before the add field button.
parentLinearLayout.addView(rowView, parentLinearLayout.getChildCount() - 1);
}

public void onDelete(View v) {
parentLinearLayout.removeView((View) v.getParent());
}


activity.xml



 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/parent_linear_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:orientation="vertical" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal" >
<EditText
android:id="@+id/edit_text"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="5"
android:inputType="text"/>
<Button
android:id="@+id/delete_button"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="1"
android:background="@android:drawable/ic_delete"
android:onClick="onDelete"/>
</LinearLayout>
<Button
android:id="@+id/add_field_button"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="#555"
android:layout_gravity="center"
android:onClick="onAddField"
android:textColor="#FFF"
android:text="Add Field"
android:paddingLeft="5dp"/>
<TextView
android:layout_marginTop="10dp"
android:gravity="center"
android:id="@+id/txt"
android:text="HELLO"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>


fiel.xml



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal" >
<EditText
android:id="@+id/edit_text"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="5"
android:inputType="text"/>
<Button
android:id="@+id/delete_button"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="1"
android:background="@android:drawable/ic_delete"
android:onClick="onDelete"/>
</LinearLayout>









share|improve this question















The EditText is Dynamically added by user .
how get data from each dynamically created EditText .or get values from the dynamically created EditTexts when the user tap a save button, then store all of them , dynamically added by user and save as Share preferences or save as array thanks guys



public class ActivityOptions extends AppCompatActivity {
private LinearLayout parentLinearLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_options);
parentLinearLayout = (LinearLayout) findViewById(R.id.parent_linear_layout);

}
public void onAddField(View v) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View rowView = inflater.inflate(R.layout.field, null);
// Add the new row before the add field button.
parentLinearLayout.addView(rowView, parentLinearLayout.getChildCount() - 1);
}

public void onDelete(View v) {
parentLinearLayout.removeView((View) v.getParent());
}


activity.xml



 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/parent_linear_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:orientation="vertical" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal" >
<EditText
android:id="@+id/edit_text"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="5"
android:inputType="text"/>
<Button
android:id="@+id/delete_button"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="1"
android:background="@android:drawable/ic_delete"
android:onClick="onDelete"/>
</LinearLayout>
<Button
android:id="@+id/add_field_button"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="#555"
android:layout_gravity="center"
android:onClick="onAddField"
android:textColor="#FFF"
android:text="Add Field"
android:paddingLeft="5dp"/>
<TextView
android:layout_marginTop="10dp"
android:gravity="center"
android:id="@+id/txt"
android:text="HELLO"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>


fiel.xml



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal" >
<EditText
android:id="@+id/edit_text"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="5"
android:inputType="text"/>
<Button
android:id="@+id/delete_button"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="1"
android:background="@android:drawable/ic_delete"
android:onClick="onDelete"/>
</LinearLayout>






android android-studio






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 14:40







Droid Projects

















asked Nov 23 '18 at 12:33









Droid ProjectsDroid Projects

33




33












  • Your code doesn't have any EditText related code. Only post code that is relevant to the question.
    – Lekr0
    Nov 23 '18 at 13:55










  • the EditText is Dynamically Added !
    – Droid Projects
    Nov 23 '18 at 14:33




















  • Your code doesn't have any EditText related code. Only post code that is relevant to the question.
    – Lekr0
    Nov 23 '18 at 13:55










  • the EditText is Dynamically Added !
    – Droid Projects
    Nov 23 '18 at 14:33


















Your code doesn't have any EditText related code. Only post code that is relevant to the question.
– Lekr0
Nov 23 '18 at 13:55




Your code doesn't have any EditText related code. Only post code that is relevant to the question.
– Lekr0
Nov 23 '18 at 13:55












the EditText is Dynamically Added !
– Droid Projects
Nov 23 '18 at 14:33






the EditText is Dynamically Added !
– Droid Projects
Nov 23 '18 at 14:33














1 Answer
1






active

oldest

votes


















1














You could retrieve the value by looping the parentView, something like this



ArrayList getEditTextList()
{

ArrayList<String> list = new ArrayList<String>();
int size = parentLinearLayout.getChildCount()

for (int i=0 ; i < size ; i++)
{
View view = parentLinearLayout.getChildAt(i);
EditText text = view.findViewById(R.id.yourEditTextName);
list.add(text.getText().toString());
}
return list;
}


Later you can add the values to Shared preference either by converting Arraylist to Json String or Adding it one by one.






share|improve this answer























  • error: incompatible types: unexpected return value
    – Droid Projects
    Nov 23 '18 at 15:09










  • android.widget.EditText.getText()' on a null object reference
    – Droid Projects
    Nov 23 '18 at 15:15










  • Have you changed view.findViewById(R.id.yourEditTextName); to view.findViewById(R.id.edit_text);.
    – Adi
    Nov 24 '18 at 20:07













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%2f53446798%2fhow-to-get-text-from-all-edittext-dynamically-added-in-a-row%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














You could retrieve the value by looping the parentView, something like this



ArrayList getEditTextList()
{

ArrayList<String> list = new ArrayList<String>();
int size = parentLinearLayout.getChildCount()

for (int i=0 ; i < size ; i++)
{
View view = parentLinearLayout.getChildAt(i);
EditText text = view.findViewById(R.id.yourEditTextName);
list.add(text.getText().toString());
}
return list;
}


Later you can add the values to Shared preference either by converting Arraylist to Json String or Adding it one by one.






share|improve this answer























  • error: incompatible types: unexpected return value
    – Droid Projects
    Nov 23 '18 at 15:09










  • android.widget.EditText.getText()' on a null object reference
    – Droid Projects
    Nov 23 '18 at 15:15










  • Have you changed view.findViewById(R.id.yourEditTextName); to view.findViewById(R.id.edit_text);.
    – Adi
    Nov 24 '18 at 20:07


















1














You could retrieve the value by looping the parentView, something like this



ArrayList getEditTextList()
{

ArrayList<String> list = new ArrayList<String>();
int size = parentLinearLayout.getChildCount()

for (int i=0 ; i < size ; i++)
{
View view = parentLinearLayout.getChildAt(i);
EditText text = view.findViewById(R.id.yourEditTextName);
list.add(text.getText().toString());
}
return list;
}


Later you can add the values to Shared preference either by converting Arraylist to Json String or Adding it one by one.






share|improve this answer























  • error: incompatible types: unexpected return value
    – Droid Projects
    Nov 23 '18 at 15:09










  • android.widget.EditText.getText()' on a null object reference
    – Droid Projects
    Nov 23 '18 at 15:15










  • Have you changed view.findViewById(R.id.yourEditTextName); to view.findViewById(R.id.edit_text);.
    – Adi
    Nov 24 '18 at 20:07
















1












1








1






You could retrieve the value by looping the parentView, something like this



ArrayList getEditTextList()
{

ArrayList<String> list = new ArrayList<String>();
int size = parentLinearLayout.getChildCount()

for (int i=0 ; i < size ; i++)
{
View view = parentLinearLayout.getChildAt(i);
EditText text = view.findViewById(R.id.yourEditTextName);
list.add(text.getText().toString());
}
return list;
}


Later you can add the values to Shared preference either by converting Arraylist to Json String or Adding it one by one.






share|improve this answer














You could retrieve the value by looping the parentView, something like this



ArrayList getEditTextList()
{

ArrayList<String> list = new ArrayList<String>();
int size = parentLinearLayout.getChildCount()

for (int i=0 ; i < size ; i++)
{
View view = parentLinearLayout.getChildAt(i);
EditText text = view.findViewById(R.id.yourEditTextName);
list.add(text.getText().toString());
}
return list;
}


Later you can add the values to Shared preference either by converting Arraylist to Json String or Adding it one by one.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 26 '18 at 8:53

























answered Nov 23 '18 at 13:40









AdiAdi

264




264












  • error: incompatible types: unexpected return value
    – Droid Projects
    Nov 23 '18 at 15:09










  • android.widget.EditText.getText()' on a null object reference
    – Droid Projects
    Nov 23 '18 at 15:15










  • Have you changed view.findViewById(R.id.yourEditTextName); to view.findViewById(R.id.edit_text);.
    – Adi
    Nov 24 '18 at 20:07




















  • error: incompatible types: unexpected return value
    – Droid Projects
    Nov 23 '18 at 15:09










  • android.widget.EditText.getText()' on a null object reference
    – Droid Projects
    Nov 23 '18 at 15:15










  • Have you changed view.findViewById(R.id.yourEditTextName); to view.findViewById(R.id.edit_text);.
    – Adi
    Nov 24 '18 at 20:07


















error: incompatible types: unexpected return value
– Droid Projects
Nov 23 '18 at 15:09




error: incompatible types: unexpected return value
– Droid Projects
Nov 23 '18 at 15:09












android.widget.EditText.getText()' on a null object reference
– Droid Projects
Nov 23 '18 at 15:15




android.widget.EditText.getText()' on a null object reference
– Droid Projects
Nov 23 '18 at 15:15












Have you changed view.findViewById(R.id.yourEditTextName); to view.findViewById(R.id.edit_text);.
– Adi
Nov 24 '18 at 20:07






Have you changed view.findViewById(R.id.yourEditTextName); to view.findViewById(R.id.edit_text);.
– Adi
Nov 24 '18 at 20:07




















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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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%2f53446798%2fhow-to-get-text-from-all-edittext-dynamically-added-in-a-row%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

What visual should I use to simply compare current year value vs last year in Power BI desktop

Alexandru Averescu

Trompette piccolo