//获取listview对象
ListView listView=(ListView) findViewById(R.id.lv);
//设置listview的适配器
listView.setAdapter(new MyAdapter());
class MyAdapter extends BaseAdapter{
//返回一个listView的行数
public int getCount() {
// TODO Auto-generated method stub
return li.size();
}
//返回一个view对面进行一行显示
public View getView(int position, View convertView, ViewGroup parent) {
ren r=li.get(position);
View view=null;
//判断convertView里有没有缓存
if(convertView==null){
//ager1:上下文对象
//ager2:资源文件
}else{
view=convertView;
}
//使用listview中的缓存时最好是重新设置一下数据,要不是会出现bug
//ager1:返回当前行数
//ager2:返回listview的缓存
view=View.inflate(MainActivity.this, R.layout.ren, null);
TextView name=(TextView) view.findViewById(R.id.textView1);
TextView phone=(TextView) view.findViewById(R.id.textView2);
TextView salary=(TextView) view.findViewById(R.id.textView3);
name.setText(r.getName());
salary.setText(r.getPhone());
phone.setText(r.getSalary()+"");
return view;
}
public Object getItem(int position) {
// TODO Auto-generated method stub return null;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
}