【发布时间】:2014-03-01 09:17:46
【问题描述】:
我在 Android 中向 TextView 显示列表数据时遇到了一点问题。我的场景是我有一个 TableLayout 和默认一个 TableRow。在表格行内,我创建了新的 LinearLayout。然后,在 LinearLayout 内创建了四个 TextView。我为此文本视图添加了一些默认值。我的默认值是
1, 2014-02-05, S02, 20
这是我上面场景0的代码sn-p。
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/sync_history_table_color"
android:id="@+id/history_table"
android:orientation="vertical"
>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="1dp"
android:id="@+id/row_start">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="30dp" android:id="@+id/row_linear" android:layout_weight="1"
android:background="@color/isp_home_color">
<TextView android:layout_width="0dp" android:layout_height="match_parent" android:text="@string/sync_default_no"
android:id="@+id/history_display_no" android:layout_weight="0.165"
android:gravity="center_vertical|left" android:paddingLeft="10dp"
android:textColor="@color/sync_history_text_color"/>
<TextView android:layout_width="0dp"
android:layout_height="match_parent"
android:text="@string/sync_default_date"
android:id="@+id/history_display_date"
android:layout_weight="0.5"
android:layout_gravity="center"
android:gravity="center"
android:textColor="@color/sync_history_text_color"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="@string/sync_default_order"
android:id="@+id/history_display_orderid"
android:layout_weight="0.5"
android:layout_gravity="center"
android:gravity="center"
android:textColor="@color/sync_history_text_color"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="@string/sync_default_qty"
android:id="@+id/history_display_quantity" android:layout_weight="0.5" android:layout_gravity="center"
android:gravity="center"
android:textColor="@color/sync_history_text_color"/>
</LinearLayout>
</TableRow>
</TableLayout>
其实我想动态创建TableRow、LinearLayout和TextView。然后,我把列表结果添加到这些。列表结果来自 sqlite db。但是,我得不到我想要的。这是我用于循环列表并显示结果的代码。但是,我得到了我的一些默认值。请指出我怎样才能得到这个。谢谢。
这里 sn-p 显示列表。
public void displayHistory(){
List<IspHistoryListObject> historyList = sqlaccess.getAllItems();
TableLayout showRow = (TableLayout) findViewById(R.id.history_table);
int count = 0;
for(IspHistoryListObject hl : historyList) {
count++;
TableRow tr = new TableRow(this);
LinearLayout ll = new LinearLayout(this);
ll.setLayoutParams(new LinearLayout.LayoutParams(50,30));
TextView tv_sync_no = new TextView(this);
TextView tv_sync_date = new TextView(this);
TextView tv_sync_orderid = new TextView(this);
TextView tv_sync_qty = new TextView(this);
tv_sync_no.setText(String.valueOf(count));
tv_sync_date.setText(hl.getSyncDate().substring(0,10));
tv_sync_orderid.setText(hl.getSyncOrderIdRef());
tv_sync_qty.setText(String.valueOf(hl.getQty()));
ll.addView(tv_sync_no);
ll.addView(tv_sync_date);
ll.addView(tv_sync_orderid);
ll.addView(tv_sync_qty);
tr.addView(ll);
showRow.addView(tr);
}
}
【问题讨论】:
-
我建议您为此使用
ListView。 -
我不明白问题出在哪里,您在布局中设置了默认值,并且不会在代码中显示它们???
-
@mohammed momn 实际上,当我没有从 sqlite 获得空值时,我想显示默认值。我想动态创建这个布局。
-
据我所知,如果光标中有数据,则需要删除第一个线性(默认)?
-
我想,我应该试试 ListView
标签: android sqlite android-layout