MainActivity.java 这里只贴出修改的地方,其实也就是修改了 getView的几条语句而已。这里写出 getView方法的内容
public View getView(int position, View convertView, ViewGroup parent) { Girl girl = girList.get(position); /* TextView tv = new TextView(MainActivity.this); tv.setTextSize(18); //获取集合中的元素 tv.setText(girl.toString());*/ View v ; /* * 做判断是为了listview的性能优化,converView表示一个缓冲区域。 * 在看过的条目,离开屏幕后,其实会被缓冲起来,所以我们没必要 * 每一次都去 填充,可以先判断是否有缓冲 * * */ if(convertView ==null){ //把ListView的布局文件填充为View对象 v = View.inflate(MainActivity.this, R.layout.list_layout, null); }else{ v = convertView ; } /*v.findViewById(R.id.name);前面加v是因为找的布局文件元素是listView对象的 * 而v加载的布局文件就是listview的布局文件 */ TextView name = (TextView)v.findViewById(R.id.name); name.setText(girl.getName()); TextView age = (TextView) v.findViewById(R.id.age); age.setText(girl.getAge()+""); TextView phone = (TextView)v.findViewById(R.id.phone); phone.setText(girl.getPhone()); return v; }
ListView显示Sqlite的数据美化版与性能优化
标签:
本文系统来源:http://www.cnblogs.com/linfenghp/p/5415153.html
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!