Erstellen einer XML für dynamisch erstellte Elemente

Ich möchte XML für dasTextViews undEditTexts created dynamisch. Etwas blogs vorschlagen, dass es einigeThird Party Libraries das kann das, aber ich konnte keine finden. Ich erstelle im GrundeTextViews & EditTexts dynamisch in meinem Code auf einembutton klicken

Code

      LinearLayout linearLayout1 = (LinearLayout) findViewById(R.id.linearLayout1);
        for (int x = 0; x < 1; x++) {
            Display display = ((WindowManager) getApplicationContext()
                    .getSystemService(Context.WINDOW_SERVICE))
                    .getDefaultDisplay();
            int width = display.getWidth() / 3;

            TextView et1 = new TextView(this);
            et1.setBackgroundColor(color.transparent);
            et1.setText("Untitled");
            et1.setGravity(Gravity.LEFT);
            EditText et = new EditText(this);
            et.setHint("Click to add");
            et.setInputType(InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);

            LayoutParams lp1 = new LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            LayoutParams lp2 = new LayoutParams(width,
                    LayoutParams.WRAP_CONTENT);
            // lp1.addRule(RelativeLayout.BELOW, et1.getId());

            linearLayout1.addView(et1, lp2);
            linearLayout1.addView(et, lp2);

XML:

    <ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentTop="true"
    android:layout_toRightOf="@+id/addImage" >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
    </LinearLayout>
</ScrollView>

<Button
    android:id="@+id/addEdit"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_toLeftOf="@+id/scrollView1"
    android:text="Edit" />

Die Frage ist, wie erreiche ich dieXML für dasTextView & EditText Als einString Wert? Gebe ich ihnentags undids statisch in demCod oder gibt es einen anderen weg?

Lösung XmlSerializer ist die Antwort auf die Frage. Danke für nichts. :)

  public static final void writeMapXml(Map val, String name, XmlSerializer out)
  throws XmlPullParserException, java.io.IOException
{
    if (val == null) {
        out.startTag(null, "TextView");
        out.endTag(null, "TextView");
        return;
    }

    Set s = val.entrySet();
    Iterator i = s.iterator();

    out.startTag(null, "TextView");
    if (name != null) {
        out.attribute(null, "name", "TextView");
    }

    out.endTag(null, "TextView");
}

Antworten auf die Frage(1)

Ihre Antwort auf die Frage