Dynamisch hinzufügen, Bearbeiten von text zu einem layout

Ich versuche, fügen Sie ein edit-text-Ansicht dynamisch auf ein layout aus der java-Klasse. Aber von dem, was ich umgesetzt haben, ändert sich nichts an meiner Aktion. Dies ist, was ich habe:

public final void onCreate(final Bundle i){
    int value = 0;

    isEdit = false;

    try
    {
        super.onCreate(i);

        this.setContentView(R.layout.contactedit);
        ContactList.soundIndicator = 0;
        etPhoneNumber = new ArrayList<EditText>();
        this.etPhoneNumber.add((EditText) this.findViewById(R.id.etPhoneNumberInput));

        this.addNumberBtn = (Button) this.findViewById(R.id.addNumberEditText);
        addNumberBtn.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                //etPhoneNumber.add(new EditText(ContactEdit.this));
                try{
                    LinearLayout layout = (LinearLayout) findViewById(R.id.contacteditll);

                    EditText temp = new EditText(ContactEdit.this);
                    temp.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
                            LayoutParams.WRAP_CONTENT));                

                    etPhoneNumber.add(temp);

                    layout.addView(temp);
                }catch(Exception e){
                    Log.d(TAG, "Failed to create new edit text");
                }
            }
        });
}

Dies ist die 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="wrap_content" 
  android:baselineAligned="true" 
  android:orientation="vertical"
  android:id="@+id/contacteditll"
  android:background="@drawable/darkimg">

       <TextView
        android:id="@+id/titlePrint"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/titlePrompt"
        />

      <Spinner 
        android:id="@+id/spContactTitle"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:prompt="@string/titlePrompt"
        />

    <TextView 
     android:text="@string/namePrint"
     android:id="@+id/namePrint" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content">
     </TextView>

    <EditText android:layout_width="match_parent" 
    android:hint="@string/returnName" 
    android:id="@+id/etFirstNameInput" 
    android:layout_height="wrap_content"
    android:layout_toRightOf= "@+id/namePrint">
    </EditText>

     <TextView 
     android:text="@string/secondPrint"
     android:id="@+id/secondPrint" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content">
     </TextView>

    <EditText android:layout_width="match_parent" 
    android:hint="@string/returnName" 
    android:id="@+id/etSecondNameInput" 
    android:layout_height="wrap_content"
    android:layout_toRightOf= "@+id/namePrint">
    </EditText>

    <TextView android:id="@+id/numberPrint"
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:text="@string/numberPrint">
    </TextView>

    <EditText android:layout_height="wrap_content" 
    android:layout_width="match_parent" 
    android:id="@+id/etPhoneNumberInput" 
    android:hint="@string/returnNumber">
    </EditText>

    <Button android:id="@+id/addNumberEditText"
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content"
        android:freezesText="true"
    android:editable="false"
    android:text="ADD"
    />


     <include 
     android:id="@+id/customedittext"
     layout="@layout/myedittext"/>

    <TextView android:id="@+id/emailPrint" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:text="@string/emailPrint">
    </TextView>

    <EditText android:layout_height="wrap_content" 
    android:layout_width="match_parent" 
    android:id="@+id/etEmailAddressInput" 
    android:hint="@string/returnEmail">
    </EditText>

    <Button 
    android:freezesText="true"
    android:editable="false"
    android:layout_gravity="center" 
    android:layout_height="wrap_content" 
    android:id="@+id/btnSaveButton" 
    android:layout_width="wrap_content"  
    android:text="@string/save"
    android:layout_below="@+id/emailInput" 
   />

</LinearLayout>

Immer wenn ich auf meine Schaltfläche die Aktion zu hören ist, aber nichts getan wird. Das layout der Seite nicht ändert, obwohl der neue text Bearbeiten ist in der Liste meiner Texte Bearbeiten und ich füge den neuen text Bearbeiten, um das layout.

Jede Hilfe wäre geschätzt danke.

  • Was die Orientierung der contacteditll? Wenn Sie die Schaltfläche hinzufügen von xml ist es richtig arbeitet ?
  • Die Taste ist in der xml. Die Ausrichtung ist vertikal.
  • Bitte fügen Sie Ihre xml.
  • Ich fügte hinzu, die xml. Was ich versuche zu tun ist, wenn der Benutzer auf die Schaltfläche klickt, erstellen Sie eine neue text Bearbeiten, um Ihnen zu erlauben, geben Sie eine andere Zahl.
  • Ich nehme an, contacteditll ist das äußere layout enthält alle Ansichten. Es funktioniert bei mir einwandfrei. Der edittext ist Hinzugefügt in der unteren Rand des Layouts. Was die Höhe der customedittext. Ich denke, das problem hier ist, dass der edittext ist Hinzugefügt, aber es ist außerhalb des Bildschirms, fügen Sie einen Bildlauf.
  • Überprüfen Sie auch

InformationsquelleAutor Hugs | 2011-06-27
Schreibe einen Kommentar