Could somebody help me?
For example, there is the following layout:
main.xml:
<LinearLayout
android:id="@+id/linearLayout_item"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/linearLayout_item_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="@+id/editText_item_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
... Other views, skipped ...
</LinearLayout>
<Button
android:id="@+id/button_add_alias"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/button_commit"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
I use button_add_alias to add views as they needed.
((Button) findViewById(R.id.button_add_alias))
.setOnClickListener(new View.OnClickListener() {
int position = 1;
public void onClick (View v) {
View view = getLayoutInflater().inflate(R.layout.alias, null);
((LinearLayout) findViewById(R.id.linearLayout_item)).addView(view, position);
position++;
}
});
alias.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout_alias"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="@+id/editText_alias"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
... Other views, skipped ...
</LinearLayout>
So, what is the best way to get data from programmatically added editText_alias views?
Firstly, iterate through your LinearLayout using
getChildAt().Then, retrieve the first child (which in your case will be the
EditText) from your child view.