标签:
1)重写BaseAdapter的getView方法时,为了性能要使用ViewHolder和convertView
View v = null; ViewHolder viewHolder; if( convertView == null ) {//没有缓存时候 v = View.inflate(MainActivity.this, R.layout.item, null); viewHolder = new ViewHolder(); viewHolder.title = (TextView)v.findViewById(R.id.title);
v.setTag(viewHolder); //把viewholder作为tag放入v中 } else { v = convertView;//直接把带viewholder的tag的缓存赋值给v viewHolder = (ViewHolder) v.getTag();//从里面取出tag } viewHolder.title.setText(newsList.get(position).getTitle()); return v; //返回v之后,滑出屏幕作为缓存,里面有viewholder tag
2)使用XmlPullParser解析XML文件
1 XmlPullParser xp = Xml.newPullParser(); 2 try { 3 xp.setInput(is,"utf-8");//这个容易忘 4 int type = xp.getEventType(); 5 while(type != XmlPullParser.END_DOCUMENT) { 6 //解析的代码
.... 7 type = xp.next();//这个容易忘 8 } 9 } catch (Exception e) { 10 // TODO Auto-generated catch block 11 e.printStackTrace(); 12 }
标签:
原文地址:http://www.cnblogs.com/soildong/p/4639226.html