<span style="font-family:Microsoft YaHei;font-size:18px;color:#3366ff;"><strong>public class MultipleItemsList extends ListActivity { private MyCustomAdapter mAdapter; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mAdapter = new MyCustomAdapter(); for (int i = 0; i < 50; i++) { mAdapter.addItem("item " + i); } setListAdapter(mAdapter); } private class MyCustomAdapter extends BaseAdapter { private ArrayList mData = new ArrayList(); private LayoutInflater mInflater; public MyCustomAdapter() { mInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); } public void addItem(final String item) { mData.add(item); notifyDataSetChanged(); } @Override public int getCount() { return mData.size(); } @Override public String getItem(int position) { return mData.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { System.out.println("getView " + position + " " + convertView); ViewHolder holder = null; if (convertView == null) { convertView = mInflater.inflate(R.layout.item1, null); holder = new ViewHolder(); holder.textView = (TextView)convertView.findViewById(R.id.text); convertView.setTag(holder); } else { holder = (ViewHolder)convertView.getTag(); } holder.textView.setText(mData.get(position)); return convertView; } } public static class ViewHolder { public TextView textView; } }</strong></span>
参考资料:
http://www.cnblogs.com/xiaowenji/archive/2010/12/08/1900579.html
http://www.eoeandroid.com/thread-72369-1-1.html
http://www.cnblogs.com/felix-hua/archive/2012/01/06/2314436.html
http://blog.csdn.net/jacman/article/details/7087995
http://fatkun.com/2012/01/Android-viewholder.html
以上分析都是晚上搜刮加综合再加理解,希望看到这篇文章的朋友,多分享,多指教。。。