Ich habe eine Anwendung mit einem Eingabetext, wo die Benutzer eine Information und eine Schaltfläche "+" neben dem Text eingeben müssen. Ich möchte mein Formular dynamisch in einer Weise, dass, wenn ein Benutzer drückt auf "+" Taste dynamisch erscheint eine andere Texteingabe und eine weitere "+" Taste neben dieser, der Prozess wird auf die gleiche Weise wiederholt.Fügen Sie dynamisch Eingabe Text und Schaltflächen in Aktivität android
I erstellt und XML-Datei, sample_content:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/attempt"
android:layout_alignParentBottom="true"
android:text="TextView" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="36dp"
android:layout_height="32dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="22dp"
android:text="+" />
<EditText
android:layout_width="229dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginRight="14dp"
android:layout_toLeftOf="@+id/addKey"
android:background="@drawable/inputtext_corner"
android:ems="10"
android:textSize="18sp" >
<requestFocus />
</EditText>
</RelativeLayout>
und in meiner Aktivität, AddDeviceActivity Ich habe:
inflater = LayoutInflater.from(AddDeviceActivity.this);
Button addKey = (Button) findViewById(R.id.addKey);
addKey.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
final RelativeLayout canvas = (RelativeLayout) AddDeviceActivity.this.findViewById(R.id.my_canvas);
final View childView = inflater.inflate(R.layout.sample_component, canvas, false);
// TODO: Look up the 5 different signatures of the addView method,
// and pick that best fits your needs
canvas.addView(childView);
}
});
Aber diese Lösung, weil nicht funktioniert, wenn ich die erste hinzufügen Eingabe Text und die erste Taste, ich weiß nicht, wie man die zweite Taste in meiner AddDeviceActivity dynamisch