I'm a beginner in Android development and would appreciate your help on this one.
I have an android activity that creates a Checkbox and an EditText when the user clicks on a button. The user is free to add as many Checkboxes/EditTexts he likes.
This is the xml file of the view that is being added to the activity:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10" >
<requestFocus />
</EditText>
</LinearLayout>
</LinearLayout>
This is the java code :
public void onclickplus (View view){
LayoutInflater inflate = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View view1 = inflate.inflate(R.layout.row_checkitem, null);
mainLayout.addView(view1);
count = count +1;
}
My question is , how do we access these checkboxes and EditTexts added, in the actual java code so that i can save their data to my database.
If these objects where predetermined i would do for example :
EditText text1;
text1 = (EditText) findViewById(R.id.editText1);
text1.getText().toString();
and so on ,to access an editText's value.
In this case however , these objects are not there when the activity is launched.
Can you help me out? Thanks.