我試圖動態地添加在TableLayout行..但我不知道在哪裏我得到wrong..Please幫助..謝謝無法動態地添加在TableLayout排的Android
JSONObject res = new JSONObject(response);
JSONArray thread = res.getJSONArray("physician_info");
for (int i = 0; i < thread.length(); i++) {
JSONObject obj = thread.getJSONObject(i);
TableRow row= new TableRow(getActivity());
row.setLayoutParams(new TableLayout.LayoutParams(
TableLayout.LayoutParams.MATCH_PARENT,
TableLayout.LayoutParams.WRAP_CONTENT));
// row.setLayoutParams(lp);
physician_name = new TextView(getActivity());
number = new TextView(getActivity());
type =new TextView(getActivity());
physician_name.setText(obj.getString("name"));
number.setText(obj.getString("number"));
type.setText(obj.getString("type"));
row.addView(physician_name);
row.addView(number);
row.addView(type);
tbl.addView(row, new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT,TableLayout.LayoutParams.WRAP_CONTENT));
}
我有Tablelayout像
<TableLayout android:layout_width="match_parent" android:id="@+id/physicians" android:layout_height="150dp" android:shrinkColumns="*" android:stretchColumns="*" android:orientation="vertical">
<TableRow android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal">
<TextView android:layout_width="match_parent" android:textStyle="" android:layout_height="wrap_content" android:text="Phyisician" android:textColor="#000" android:layout_margin="1dp" android:gravity="center" />
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Number" android:textColor="#000" android:gravity="center" android:layout_margin="1dp"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Type" android:textColor="#000" android:gravity="center" android:layout_margin="1dp" /> </TableRow></TableLayout>
'
我想動態地在上面這行的底部添加行。
請參閱本http://stackoverflow.com/questions/18207470/adding-table-rows-dynamically-in-android –
的應用程序崩潰?如果是,那麼添加logcat如果沒有,那麼你面臨什麼問題? –
@SohailZahid沒有應用程序不崩潰..我從json數組中獲得完整的數據,但沒有顯示在表格行中。 –