Programmieren einer Tabellenansicht mit flexieblen Zeilen und Spaltenzahl für Android

S

SchokoMuh

Neues Mitglied
0
Hallo,
als erstes mal hoffe ich das meine Frage im richtigen Forum gelandet ist. Ich versuche mich seit ca. 5 Wochen in der kunst mein Handy mittels Java dazu zu bringen dinge zu tun die ich nicht wollte.
Ich hab da mal ein kleines Programm geschrieben das mir eigentlich eine Tabelle auf dem Smartphone anzeigen soll. Das befüllen läuft später mit einer Datenbank aber ich habe schon bei der Ansicht das problem das mir nur 2 Zeilen angelegt werden und ich finde den fehler einfach nicht. Würde mich freuen wenn jemand einen tipp hätte.
Hier mal meine MainActivity:

package com.example.tabellentest;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

String[] textArray ={" Null "," Eins ", " Zwei ", " Drei ", " Vier ", " Fünf "," SechsHundertZweiUndDreizig ", " Sechs "};
String[] textArray1 ={" 12Null "," 12Eins ", " 12Zwei ", " 12Drei ", " 12Vier ", " 12Fünf "," 12SechsHundertZweiUndDreizig ", " Sechs "};

private TableLayout firstTable;
private TableLayout secondTable;

@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ExpandTextView();
this.firstTable = (TableLayout) findViewById(R.id.tableLayout1);
this.secondTable = (TableLayout) findViewById(R.id.tableLayout2);

ExpandTableRow();
}
public TextView CreateTextView(String text, int index){
TextView textView1 = new TextView(getApplicationContext());
textView1.setText(text);
return textView1;
}
public void ExpandTextView (){
LinearLayout linearLayout = findViewById(R.id.linearLayout1);
for( int i = 0; i < textArray.length; i++ )
{
linearLayout.addView(CreateTextView(textArray, i));
TextView textView = new TextView(this);
//textView.setText(textArray);
//textView.setId(i);
linearLayout.addView(textView);
}
}
public void ExpandTableRow(){
for (int ab = 2; ab <= 8; ab++){
LinearLayout linearLayout2 = findViewById(R.id.linearLayout2);
for( int i = 0; i < textArray1.length; i++ ) {
linearLayout2.addView(CreateTextView(textArray1, i));
}
Context context = getApplicationContext();
TableRow row = new TableRow(context);
secondTable.addView(row);
for( int i = 0; i < textArray1.length; i++ ) {
linearLayout2.addView(CreateTextView(textArray1, i));
}
}
}
}

und die Activity_Main.xml:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<HorizontalScrollView
android:id="@+id/horizontalScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="64dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<ScrollView
android:layout_width="wrap_content"
android:layout_height="match_parent">

<TableLayout
android:id="@+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TableRow
android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"/>
</TableRow>
</TableLayout>
</ScrollView>
</HorizontalScrollView>

<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="80dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<TableLayout
android:id="@+id/tableLayout2"
android:layout_width="wrap_content"
android:layout_height="match_parent">

<TableRow
android:id="@+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" />
</TableRow>

</TableLayout>
</HorizontalScrollView>

</androidx.constraintlayout.widget.ConstraintLayout>
 
Du solltest dringend CODE-Tags benutzen, sonst ist dein Code (wie oben) nur unvollständig zu sehen und scheiße eingerückt. Das macht das Helfen auch nicht gerade leicht.
 
Zuletzt bearbeitet:

Ähnliche Themen

T
Antworten
2
Aufrufe
218
DOT2010
DOT2010
D
Antworten
5
Aufrufe
666
dtp
D
Zurück
Oben Unten