1
我是一个新手,我创建了一个应用程序,我得到一个Json对象与大量的数据。我必须解析它并显示TableLayout
上的值,但我想动态创建TableRows
。我也读过,我们应该使用GridView
来显示动态数据,但我认为网格视图是用于图像的,但是我有5列和许多行(可能是100s)取决于数据。我没有找到任何解决方案。我找不到任何教程。使用TableLayout动态分析Json
我的代码是
<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
但不能动态地进行。这款应用只支持大型平板电脑。
我一直在寻找这个。谢谢 – devloperuser