I have a LinearLayout
(say parent) in whcih i'm inflating another LinearLayout
(say child) which contains an EditText
& ImageButton
.
I am inflating child layout on click of a button in main layout. When one clicks on ImageButton
of child layout that layout is gets removed. I have setup this with no problem.
Now I want to get text of all the EditText
of child layout,when one click Save button of ActionBar
.
Following is the method that I'm using to inflate my view. And mainLayout
is my parent layout. Now how can I get text of all added EditText
anywhere in my activity ?
private void addEditView(final LinearLayout mainLayout) {
LayoutInflater inflater = LayoutInflater.from(this);
View theInflatedView = inflater.inflate(R.layout.layout_add_phone_number_listview, null);
//Get the EditText in you xml to set the new id
EditText editText = (EditText) theInflatedView.findViewById(R.id.et_pn);
editText.setId(4000+1);//mainLayout.getChildCount()
ImageButton remove = (ImageButton) theInflatedView.findViewById(R.id.btn_remove_raw);
remove.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
mainLayout.removeView((View)v.getParent());
}
});
//add the view into the LinearLayout (global variable)
mainLayout.addView(theInflatedView);
}
What have I tried :
LinearLayout ll = (LinearLayout)findViewById(R.id.phone_info);
int count = ll.getChildCount();
for(int i =0;i<count;i++)
{
Log.e("child count:", "count:" + count + "ID:" + ll.getChildAt(i).getId());
View vi = ll.getChildAt(i);
if(vi instanceof EditText)
{
// you got the spinner
EditText s = (EditText) findViewById(4000+i);
Log.e("Item selected",s.getText().toString());
}
}