Android表格布局

时间:2015-10-22 09:05:04

标签: java android xml layout

我使用TableLayout在Android中创建了一个表。然而,我只需要在表格中显示字符串,是否有其他或更简单的方法在Android中创建纯文本表格?

tableLayout.xml:

<TableLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tableLayout"
    android:layout_height="match_parent"
    android:layout_width="fill_parent"
    android:shrinkColumns="*"
    android:stretchColumns="*">

    <TableRow
        android:id="@+id/protokolleTitel"
        android:background="#FFF"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="1dp"
        android:gravity="center">
        <TextView
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:id="@+id/protokolleDatum"
            android:text="Datum"
            android:textStyle="bold"
            android:gravity="center"/>

        <TextView
            android:id="@+id/protokolleInhalt"
            android:text="Inhalt"
            android:textStyle="bold"
            android:gravity="center"/>

        <TextView
            android:id="@+id/protokolleKontostand"
            android:text="Kontostand"
            android:textStyle="bold"
            android:gravity="center"/>

    </TableRow>

    <View
        android:id="@+id/protokolleSeperator"
        android:layout_height="2dp"
        android:background="#000"
        android:layout_margin="2dp"/>

    <TableRow
        android:id="@+id/protokoll1"
        android:background="#FFF"
        android:layout_margin="1dp">
        <TextView
            android:id="@id/datum1"
            android:text="29.05.2015"
            android:gravity="center"/>

        <TextView
            android:id="@+id/anmerkung1"
            android:text="Abrechnung 2 h\n Korrekturlesen von Anna"
            android:gravity="center"/>

        <TextView
            android:id="@+id/kontostand1"
            android:text="2"
            android:gravity="center"/>
    </TableRow>
    <TableRow
        android:id="@+id/protokoll2"
        android:onClick="@string/protokollDetails"
        android:baselineAligned="true"
        android:background="#FFF"
        android:layout_margin="1dp">
        <TextView
            android:id="@id/datum2"
            android:text="28.05.2015"
            android:gravity="center"/>

        <TextView
            android:id="@+id/anmerkung2"
            android:text="Korrekturlesen\n einer Facharbeit"
            android:gravity="center"/>

        <TextView
            android:id="@+id/kontostand2"
            android:text="-2"
            android:gravity="center"/>

    </TableRow>

</TableLayout>

Activity.java:

public class Stundenprotokolle extends AppCompatActivity{


//Deklaration der Tabellen Spalten

private TableRow row1;
private TableRow row2;
private TableRow row3;
private Intent toDetails;

//Deklaration der TextViews pro Spalte
TextView protokoll1Datum;
TextView protokoll1Inhalt;
TextView protokoll1Kontostand;

TextView protokoll2Datum;
TextView protokoll2Inhalt;
TextView protokoll2Kontostand;

TextView protokoll3Datum;
TextView protokoll3Inhalt;
TextView protokoll3Kontostand;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_nachhilfe_stundenprotokolle);

    //Initialisierung der TextViews
    //TODO text aus soap return setzen
    protokoll1Datum = (TextView) findViewById(R.id.protokollDatum1);
    protokoll1Inhalt = (TextView) findViewById(R.id.protokollInhalt1);
    protokoll1Kontostand = (TextView) 
findViewById(R.id.protokollKontostand1);

    protokoll2Datum = (TextView) findViewById(R.id.protokollDatum2);
    protokoll2Inhalt = (TextView) findViewById(R.id.protokollInhalt2);
    protokoll2Kontostand = (TextView)
findViewById(R.id.protokollKontostand2);

    protokoll3Datum = (TextView) findViewById(R.id.protokollDatum3);
    protokoll3Inhalt = (TextView) findViewById(R.id.protokollInhalt3);
    protokoll3Kontostand = (TextView)
 findViewById(R.id.protokollKontostand3);


    Toast.makeText(Stundenprotokolle.this,"Protokolle für Details 
  anklicken",Toast.LENGTH_LONG).show();

    toDetails = new Intent(Stundenprotokolle.this, 
 ProtokollDetails.class);


    row1 = (TableRow) findViewById(R.id.protokoll1);
    row1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            startActivity(toDetails);

        }
    });

    row2 = (TableRow) findViewById(R.id.protokoll2);
    row2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            startActivity(toDetails);
        }
    });


}
}

0 个答案:

没有答案