【发布时间】:2015-07-21 14:38:15
【问题描述】:
我是一个新手,我正在创建一个应用程序,我在其中获取一个包含大量数据的 json 对象。我必须解析它并在TableLayout 上显示值,但我想动态创建TableRows。我还读到我们应该使用GridView 来显示动态数据,但我认为网格视图是用于图像的,但我有 5 列和许多行(可能是 100 行)取决于数据。我没有找到任何解决方案。我找不到任何教程。
我的代码是
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E57373"
tools:context="com.example.myapp.AfterLogin"
android:screenOrientation="userLandscape">
<LinearLayout
android:layout_marginTop="100dp"
android:layout_width="250dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/linearLayout"
android:background="#9E9E9E">
</LinearLayout>
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignTop="@+id/linearLayout"
android:layout_toEndOf="@+id/linearLayout"
android:stretchColumns="*">
<TableRow
android:layout_height="40dp"
android:layout_width="match_parent"
>
<TextView
android:layout_width="match_parent"
android:layout_height="25dp"
android:textSize="18sp"
android:textColor="@android:color/black"
android:text="@string/tasInsp"
android:id="@+id/textView3"
android:gravity="center"
android:layout_span="5"
android:background="#9E9E9E"/>
</TableRow>
<TableRow
android:layout_height="40dp"
android:layout_width="match_parent"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="42dp"
android:textSize="18sp"
android:textColor="@android:color/black"
android:text="@string/sNo"
android:id="@+id/textView4"
android:gravity="center"
android:background="#00E5FF"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="42dp"
android:textSize="18sp"
android:textColor="@android:color/black"
android:text="@string/reNo"
android:id="@+id/textView5"
android:gravity="center"
android:background="#CDDC39"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="42dp"
android:textSize="18sp"
android:textColor="@android:color/black"
android:text="@string/impoame"
android:id="@+id/textView6"
android:gravity="center"
android:background="#00E5FF"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="42dp"
android:textSize="18sp"
android:textColor="@android:color/black"
android:text="@string/custNo"
android:id="@+id/textView7"
android:gravity="center"
android:background="#CDDC39"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="42dp"
android:textSize="18sp"
android:textColor="@android:color/black"
android:text="@string/custDate"
android:id="@+id/textView8"
android:gravity="center"
android:background="#00E5FF"
/>
</TableRow>
</TableLayout>
</RelativeLayout>
我知道如何在 xml 中创建 TableLayout,但不能动态创建。此应用仅支持大型平板电脑。
【问题讨论】:
标签: android android-tablelayout