【发布时间】:2014-01-17 21:08:53
【问题描述】:
在我的 Android 应用程序中,我必须在 layout 表中显示从数据库中获取的数据。我得到数据,当我将 TableRaws 添加到 Table 时,它会给出一个空指针。我正确实例化表中的元素,但我无法找出错误。我的代码 sn-p 如下....
TableLayout tbl=(TableLayout) findViewById(R.id.dpl_tbl_lst);
if(!retailersList.isEmpty()){
//TableRow Hedding=(TableRow) findViewById(R.id.dpl_tbl_hdr);
//tbl.addView(Hedding);
for(int i=0;i<retailersList.size();i++){
Retailer RtlIns=retailersList.get(i);
TableRow tbl_rw=(TableRow) findViewById(R.id.dpl_tbr_cnt);
TextView sequence, custommerName, city, status;
sequence=(TextView) findViewById(R.id.dpl_txt_seq);
custommerName=(TextView) findViewById(R.id.dpl_txt_cus_nm);
city=(TextView) findViewById(R.id.dpl_txt_cty);
status=(TextView) findViewById(R.id.dpl_txt_sts);
sequence.setText(RtlIns.getPosition());
custommerName.setText(RtlIns.getName());
city.setText(RtlIns.getCity());
status.setText(RtlIns.getStatus());
tbl_rw.addView(sequence);
tbl_rw.addView(custommerName);
tbl_rw.addView(city);
tbl_rw.addView(status);
tbl.addView(tbl_rw);}
我的表格布局如下.....
<TableLayout
android:id="@+id/dpl_tbl_lst"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow
android:id="@+id/dpl_tbl_hdr"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textview3"
android:layout_width="@dimen/cell_width_0"
android:layout_height="@dimen/cell_h_h"
android:background="@drawable/cell_shape"
android:padding="@dimen/cell_pdn"
android:text="@string/list_sequense"
android:textColor="@color/white"
android:textSize="@dimen/normal_text"
android:textStyle="bold" />
<TextView
android:layout_width="@dimen/cell_width_2"
android:layout_height="@dimen/cell_h_h"
android:background="@drawable/cell_shape"
android:padding="@dimen/cell_pdn"
android:text="@string/list_cust_name"
android:textColor="@color/white"
android:textSize="@dimen/normal_text"
android:textStyle="bold" />
<TextView
android:layout_width="@dimen/cell_width_2"
android:layout_height="@dimen/cell_h_h"
android:background="@drawable/cell_shape"
android:padding="@dimen/cell_pdn"
android:text="@string/list_city"
android:textColor="@color/white"
android:textSize="@dimen/normal_text"
android:textStyle="bold" />
<TextView
android:layout_width="@dimen/cell_width_1"
android:layout_height="@dimen/cell_h_h"
android:background="@drawable/cell_shape"
android:padding="@dimen/cell_pdn"
android:text="@string/list_status"
android:textColor="@color/white"
android:textSize="@dimen/normal_text"
android:textStyle="bold" />
</TableRow>
</TableLayout>
有人可以帮我解决这个问题吗?
【问题讨论】:
-
发布 logcat 错误消息。
标签: android android-layout tablelayout