1.for循环手动添加View进入ListView。
//获取布局控件
LinearLayout l = (LinearLayout) findViewById(R.id.l);
PersonDao dao=new PersonDao(this)
List<Person> persons=dao.findAll();
for(Person person : persons)
{
String info = person.toString;
TextView tv = new TextView(this);
tv.setTextSize(20);
tv.setText(info);
//重点,向LinearLayout中添加新创建的textView
l.addView(tv);
}
2.BaseAdapter抽象类方法。
LinearLayout l = (LinearLayout) findViewById(R.id.l);
PersonDao dao=new PersonDao(this)
List<Person> persons=dao.findAll();
l.setAdapter(MyAdaper);
3.MyAdaperl extends BaseAdapter抽象类方法使用的扩展---使用 View.inflate() 扩展ListView的内容样式模板。
View view = View.inflate(Mainactivity.this,R.layout.list_item.null);
//下面的空间均在R.layout.list_item中已经定义过
TextView a=(TextView)findViewById(R.id.a);
a.setText("名字"+name);
TextView b=(TextView)findViewById(R.id.b);
b.setText("名字"+age);
@将上面的代码在实现继承BaseAdapter类中的getView()方法中实现
4.扩展知识----LayoutInflate
//context是上下文对象
LayoutIflate f=LayoutInflate.from(context);
//resource为布局XML文件
//f.inflate(resource,root);
通过这样的方法可以手动将一个XML布局文件转换成一个视图View