Android table

My android app has a screen with some data that will be displayed in table format. This table will contain about 5 columns and at least 50 rows.

How do I create a table in android?

I have searched and everyone seems to recommend using TableLayout and textView per cell. Using this method seems a little tricky as there are many TextView components.

Is there any other solution?

+3


source to share


3 answers


TableLayout lTableLayout;
lTableLayout = (TableLayout)findViewById(R.id.tblayout);
for(int i=0;i<10;i++){
TableRow tr1 = new TableRow(this);
tr1.setPadding(0, 5, 0, 0);
lTableLayout.addView(tr1, LayoutParams.WRAP_CONTENT,
                        LayoutParams.WRAP_CONTENT);
TextView tv11 = new TextView(this);
tv11.setPadding(2, 0, 0, 0);
tv11.setTextSize(12);
tr1.addView(tv11,LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); // Can give width and height in numbers also.

}

      

They will create 10 rows and 1 text view per row in the accepted table layout. take one table layout to your XML file as below:



<TableLayout
                    android:id="@+id/tblayout"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content" >
</TableLayout>

      

+3


source


Use ListView with custom adapter, create five textviews in listview item as columns. create a list like this row.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="match_parent">

   <TextView android:text="TextView" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
   <TextView android:text="TextView" android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
   <TextView android:text="TextView" android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
   <TextView android:text="TextView" android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
   <TextView android:text="TextView" android:id="@+id/textView5" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
</LinearLayout>

      

0


source


Not required by the TableLayout user.

you can use a custom ListView and set the title of the ListView as the column name

For creating a custom list see this example

0


source







All Articles