0
在我的Android应用程序中,我必须显示从表布局中的db获取的数据。我得到的数据,当我加入TableRaws到表它提供了一个空指针。我正确实例在表中的元素,我无法弄清楚错误。我的代码片段如下....Android在运行时将数据加载到表格布局
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的错误消息。 –
请寄给logcat。 – PsyGik