Moin, ich bastle grade an einer Art Visitorlog, und dafür brauche ich eine Tabelle, welche bei Knopfdruck sich dynamisch um eine Zeile erweitert.
Dies klappt auch zu einem bestimmten Punkt aber irgendwie bekomme ichs nicht hin, dass die eingegeben Daten unter den Spaltenüberschriften ist. Also Aligned. Könnte mir da jemand helfen? Danke bereits im Vorraus.
Clearform ist einfach eine Methode, welche die Inhalte aus den Editfields wieder leert, nichts besonderes.
Außerdem sind OnCklickListener verwendet fürs "adden" der Zeilen, hoffe das ist gut genug erklärt.
Der XML-Code sieht wie folgt aus (ist mein erstes mal XML also seid barmherzig:
Dies klappt auch zu einem bestimmten Punkt aber irgendwie bekomme ichs nicht hin, dass die eingegeben Daten unter den Spaltenüberschriften ist. Also Aligned. Könnte mir da jemand helfen? Danke bereits im Vorraus.
Java:
public void addTableRow() {
try {
String name = inputName.getText().toString();
String firma = inputFirma.getText().toString();
String ausweis = inputAusweis.getText().toString();
String besuchter = inputBesuchter.getText().toString();
String zielOrt = inputOrt.getText().toString();
String kommen = inputKommen.getText().toString();
if (inputName.getText().toString().trim().equals("") ||
inputKommen.getText().toString().trim().equals("") ||
inputAusweis.getText().toString().trim().equals("") ||
inputFirma.getText().toString().trim().equals("") ||
inputBesuchter.getText().toString().trim().equals("") ||
inputOrt.getText().toString().trim().equals("")) {
Toast.makeText(this, "Bitte füllen Sie alle Felder aus.", Toast.LENGTH_SHORT).show();
return;
}
TableLayout tableLayout = findViewById(R.id.table_layout);
TableRow tableRow = new TableRow(this);
// TableRow tableRow = findViewById(R.id.tableColorRow);
counter++;
bordCourtInt++;
try {
TextView counterView = new TextView(this);
counterView.setText(String.valueOf(counter));
TableRow.LayoutParams params1 = new TableRow.LayoutParams(0, TableRow.LayoutParams.WRAP_CONTENT, 0.2f);
counterView.setLayoutParams(params1);
tableRow.addView(counterView);
TextView nameView = new TextView(this);
nameView.setText(name);
TableRow.LayoutParams params2 = new TableRow.LayoutParams(0, TableRow.LayoutParams.WRAP_CONTENT, .2f);
nameView.setLayoutParams(params2);
tableRow.addView(nameView);
TextView firmaView = new TextView(this);
firmaView.setText(firma);
TableRow.LayoutParams params3 = new TableRow.LayoutParams(0, TableRow.LayoutParams.WRAP_CONTENT, .2f);
firmaView.setLayoutParams(params3);
tableRow.addView(firmaView);
TextView ausweisView = new TextView(this);
ausweisView.setText(ausweis);
TableRow.LayoutParams params4 = new TableRow.LayoutParams(0, TableRow.LayoutParams.WRAP_CONTENT, .2f);
ausweisView.setLayoutParams(params4);
tableRow.addView(ausweisView);
TextView kommenView = new TextView(this);
kommenView.setText(kommen);
TableRow.LayoutParams params5 = new TableRow.LayoutParams(0, TableRow.LayoutParams.WRAP_CONTENT, .2f);
kommenView.setLayoutParams(params5);
tableRow.addView(kommenView);
TextView besuchterView = new TextView(this);
besuchterView.setText(besuchter);
TableRow.LayoutParams params6 = new TableRow.LayoutParams(0, TableRow.LayoutParams.WRAP_CONTENT, .2f);
besuchterView.setLayoutParams(params6);
tableRow.addView(besuchterView);
TextView zielOrtView = new TextView(this);
zielOrtView.setText(zielOrt);
TableRow.LayoutParams params7 = new TableRow.LayoutParams(0, TableRow.LayoutParams.WRAP_CONTENT, .2f);
zielOrtView.setLayoutParams(params7);
tableRow.addView(zielOrtView);
TextView gehenView = new TextView(this);
gehenView.setText("n/a"); // "nicht vorhanden"
TableRow.LayoutParams params8 = new TableRow.LayoutParams(0, TableRow.LayoutParams.WRAP_CONTENT, .2f);
gehenView.setLayoutParams(params8);
tableRow.addView(gehenView);
Button gehenBtn = new Button(this);
gehenBtn.setText("Leave");
TableRow.LayoutParams params9 = new TableRow.LayoutParams(0, TableRow.LayoutParams.WRAP_CONTENT, .2f);
clearForm();
Außerdem sind OnCklickListener verwendet fürs "adden" der Zeilen, hoffe das ist gut genug erklärt.
Der XML-Code sieht wie folgt aus (ist mein erstes mal XML also seid barmherzig:
XML:
<TableRow
android:id="@+id/headlines"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
android:padding="5dp"
android:paddingStart="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:text="@string/nummer"
android:textColor="@color/white" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/nameHint"
android:textColor="@color/white" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/firmaHint"
android:textColor="@color/white" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/ausweisnrHint"
android:textColor="@color/white" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/kommenHint"
android:textColor="@color/white" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/besuchterHint"
android:textColor="@color/white" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/zielortHint"
android:textColor="@color/white" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/gehen"
android:textColor="@color/white" />
</TableRow>