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