首页 > 系统 > Android > 正文

Android TableLayout数据列表的回显清空实现思路及代码

2019-10-24 21:03:40
字体:
来源:转载
供稿:网友
数据列表的回显必须从后面减去子元素同时必须从后面减去子元素,感兴趣的朋友可以看下具体的实现代码,希望对你学习Android TableLayout有所帮助
 
复制代码代码如下:

//数据列表的回显 
public void shujuList(){ 
List<Customer> customerList = dao.findALL(); 
TableLayout tl = (TableLayout) findViewById(R.id.tlLayout); 
Log.i(">>>", String.valueOf(tl.getChildCount())); 
int j = tl.getChildCount(); 
if(j>1){ 
/*for(int i=0;i<j;i++){ 
tl.removeView(tl.getChildAt(j-i));//必须从后面减去子元素 
}*/ 
for(int i=j;i>0;i--){ 
tl.removeView(tl.getChildAt(i));//必须从后面减去子元素 


TableRow row = null; 
for(Customer c : customerList){ 
row = new TableRow(this); 
//id 
TextView tvId = new TextView(this); 
tvId.setText(c.id + ""); 
row.addView(tvId); 
//name 
TextView tvName = new TextView(this); 
tvName.setText(c.name); 
row.addView(tvName); 
//age 
TextView tvAge = new TextView(this); 
tvAge.setText(c.teleNumber + ""); 
row.addView(tvAge); 
tl.addView(row); 


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表