`
kanwoerzi
  • 浏览: 1643344 次
文章分类
社区版块
存档分类
最新评论

数据适配器简介(Adapter)

 
阅读更多
Android为我们提供了android.widget.Adapterandroid.widget.ExpandableListAdapter两大类数据适配器接口。
android.widget.ExpandableListAdapter接口主要和android.widget.ExpandableListView配合使用
android.widget.Adapter接口主要和android.widget.AdapterViewandroid.widget.ExpandableListView之除外的其他类配合使用。
<wbr style="line-height:25px"><div style="line-height:25px">以下是<span style="line-height:22px"><strong>Adapter</strong><span style="line-height:22px">接口及子接口和实现类</span></span>的关系图</div> <div style="line-height:25px"><span style="line-height:25px">图1:</span></div> <div style="line-height:25px"> <div style="line-height:25px"><img alt="数据适配器简介(Adapter) - hubingforever - 民主与科学" src="http://img3.ph.126.net/Rb5A2rxb0Wjg1nd9AfD01g==/2607865659241250333.png" style="line-height:25px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; max-width:100%; margin-top:0px; margin-right:10px; margin-bottom:0px; margin-left:0px"></div> </div> publicinterface<span style="line-height:25px"><span style="color:#ff00ff; line-height:25px"><wbr style="line-height:25px">Adapter</wbr></span></span><wbr style="line-height:25px"><br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">Adapter</wbr></span><wbr style="line-height:25px">是绑定Data和<a target="_blank" rel="nofollow" href="http://developer.android.com/reference/android/widget/AdapterView.html" style="color:rgb(207,121,28); line-height:25px; text-decoration:none">AdapterView</a><wbr style="line-height:25px">的适配器<br style="line-height:25px"> 实现<span style="line-height:25px"><wbr style="line-height:25px">Adapter</wbr></span><wbr style="line-height:25px">的直接接口有:<span style="color:#993300; line-height:25px">ListAdapter</span>和 <span style="color:#993300; line-height:25px"><wbr style="line-height:25px">SpinnerAdapter</wbr></span><wbr style="line-height:25px"><br style="line-height:25px"> 更多可参考《<span style="line-height:24px; font-family:Arial,Helvetica,simsun,u5b8bu4f53; white-space:nowrap"><a title="阅读全文" target="_blank" href="http://hubingforever.blog.163.com/blog/static/17104057920105113055538/" style="color:rgb(207,121,28); line-height:25px; text-decoration:none; font-weight:bold">Adapter接口</a>》</span><br style="line-height:25px"><span style="line-height:25px">一、ListAdapter</span> <div style="line-height:25px"> <span style="color:#ff00ff; line-height:25px">ListAdapter</span>是绑定Data和Listview的适配器。但是,它是接口,需要实现。<br style="line-height:25px"> 实现了<span style="line-height:25px"><wbr style="line-height:25px">ListAdapter</wbr></span><wbr style="line-height:25px">的接口有:<br style="line-height:25px"> WrapperListAdapter<br style="line-height:25px"> 实现<span style="line-height:25px"><wbr style="line-height:25px">ListAdapter</wbr></span><wbr style="line-height:25px">的类:<br style="line-height:25px"><span style="color:#993300; line-height:25px">BaseAdapter</span><br style="line-height:25px"><span style="color:#000080; line-height:25px"></span><span style="color:#0000ff; line-height:25px">ArrayAdapter&lt;T&gt;<br style="line-height:25px"> CursorAdapter</span><br style="line-height:25px"><span style="color:#3366ff; line-height:25px">ResourceCursorAdapter<br style="line-height:25px"> SimpleCursorAdapter</span><br style="line-height:25px"><span style="color:#000080; line-height:25px"> </span><span style="color:#0000ff; line-height:25px">SimpleAdapter</span><br style="line-height:25px"><span style="color:#993300; line-height:25px">HeaderViewListAdapter</span><span style="color:#000080; line-height:25px">(extendsObject)(implementsWrapperListAdapter)</span><br style="line-height:25px"> 常见的有:arrayAdapter,SimpleAdapter,CursorAdapter。<br style="line-height:25px"> ListAdapter经常和ListView一起使用,具体可参考《ListActivity和ListView》<br style="line-height:25px"><span style="line-height:25px">二、<wbr style="line-height:25px">SpinnerAdapter</wbr></span><wbr style="line-height:25px"><br style="line-height:25px"><span style="color:#ff00ff; line-height:25px">SpinnerAdapter</span>是绑定Data和Spinner的适配器.<br style="line-height:25px"> 它只申明了一个方法:<br style="line-height:25px"> abstract<a target="_blank" rel="nofollow" href="http://developer.android.com/reference/android/view/View.html" style="color:rgb(207,121,28); line-height:25px; text-decoration:none">View</a><wbr style="line-height:25px"><br style="line-height:25px"><span style="line-height:1.3em"><a target="_blank" rel="nofollow" href="http://developer.android.com/reference/android/widget/SpinnerAdapter.html#getDropDownView%28int,%20android.view.View,%20android.view.ViewGroup%29" style="color:rgb(207,121,28); line-height:25px; text-decoration:none">getDropDownView</a><wbr style="line-height:25px"></wbr></span><wbr style="line-height:25px">(intposition,<a target="_blank" rel="nofollow" href="http://developer.android.com/reference/android/view/View.html" style="color:rgb(207,121,28); line-height:25px; text-decoration:none">View</a><wbr style="line-height:25px">convertView,<a target="_blank" rel="nofollow" href="http://developer.android.com/reference/android/view/ViewGroup.html" style="color:rgb(207,121,28); line-height:25px; text-decoration:none">ViewGroup</a><wbr style="line-height:25px">parent)<span style="line-height:1.3em">Geta<a target="_blank" rel="nofollow" href="http://developer.android.com/reference/android/view/View.html" style="color:rgb(207,121,28); line-height:25px; text-decoration:none">View</a><wbr style="line-height:25px">thatdisplaysinthedropdownpopupthedataatthespecifiedpositioninthedataset.<br style="line-height:25px"></wbr></span><wbr style="line-height:25px">实现了<span style="line-height:25px"><wbr style="line-height:25px">SpinnerAdapter</wbr></span><wbr style="line-height:25px">的类:<br style="line-height:25px"><span style="color:#993300; line-height:25px">BaseAdapter</span><br style="line-height:25px"><span style="color:#0000ff; line-height:25px">ArrayAdapter<br style="line-height:25px"> CursorAdapter</span><br style="line-height:25px"><span style="color:#3366ff; line-height:25px">ResourceCursorAdapter<br style="line-height:25px"> SimpleCursorAdapter</span><br style="line-height:25px"><span style="color:#0000ff; line-height:25px">SimpleAdapter</span><br style="line-height:25px"> 实现了<span style="line-height:25px"><wbr style="line-height:25px">SpinnerAdapter</wbr></span><wbr style="line-height:25px">的接口:<br style="line-height:25px"> 无<br style="line-height:25px"> 更多可参考《<strong><a title="阅读全文" target="_blank" href="http://hubingforever.blog.163.com/blog/static/171040579201051049428/" style="color:rgb(207,121,28); line-height:25px; text-decoration:none">SpinnerAdapter</a></strong>》</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> </div> <div style="line-height:25px"> <span style="line-height:25px">三、BaseAdapte</span><br style="line-height:25px"> 关于<span style="color:#ff00ff; line-height:25px">BaseAdapte</span>请参考《<strong><a title="阅读全文" target="_blank" href="http://hubingforever.blog.163.com/blog/static/1710405792010415112116352/" style="color:rgb(207,121,28); line-height:25px; text-decoration:none">BaseAdapter</a></strong>》</div> <div style="line-height:25px"> <span style="line-height:25px">四、ArrayAdapter</span><br style="line-height:25px"><span style="color:#003366; line-height:25px"></span><span style="color:#ff00ff; line-height:25px">ArrayAdapter</span><span style="color:#003366; line-height:25px">(数组适配器)的作用就是一个数组和listview之间的桥梁,它可以将数组里边定义的数据一一对应的显示在Listview里边。<br style="line-height:25px"> ListView的每个TextView里边显示的内容就是数组里边的对象调用toString()方法后生成的字符串。</span><br style="line-height:25px"> 更多请参考《<strong><a title="阅读全文" target="_blank" href="http://hubingforever.blog.163.com/blog/static/1710405792010415114817235/" style="color:rgb(207,121,28); line-height:25px; text-decoration:none">ArrayAdapter</a></strong>》<br style="line-height:25px"><span style="line-height:25px">五、SimpleAdapter</span><br style="line-height:25px"><span style="color:#ff00ff; line-height:25px">SimpleAdapter</span>是ArrayList和ListView的桥梁。这个ArrayList里边的每一项都是一个Map&lt;String,?&gt;类型。<br style="line-height:25px"> ArrayList当中的每一项Map对象都和ListView里边的每一项进行数据绑定一一对应。<br style="line-height:25px"> 更多请参考《<strong><a title="阅读全文" target="_blank" href="http://hubingforever.blog.163.com/blog/static/171040579201043153837703/" style="color:rgb(207,121,28); line-height:25px; text-decoration:none">SimpleAdapter</a></strong>》</div> <div style="line-height:25px"> <span style="line-height:25px">六、CursorAdapter</span><br style="line-height:25px"><span style="color:#003366; line-height:25px"></span><span style="color:#ff00ff; line-height:25px">CursorAdapter</span><span style="color:#003366; line-height:25px">是个虚类,继承于</span><span style="color:#993300; line-height:25px">BaseAdapter</span><span style="color:#003366; line-height:25px">。<br style="line-height:25px"> 它有两个虚方法</span><span style="color:#ff6600; line-height:25px">newView</span><span style="color:#003366; line-height:25px">和</span><span style="color:#ff6600; line-height:25px">bindView</span><br style="line-height:25px"><span style="color:#003366; line-height:25px">直接子类只有</span><span style="color:#99cc00; line-height:25px">ResourceCursorAdapter</span><br style="line-height:25px"><span style="color:#003366; line-height:25px">间接子类只有</span><span style="color:#808000; line-height:25px">SimpleCursorAdapter</span><span style="color:#003366; line-height:25px">(它继承于</span><span style="color:#99cc00; line-height:25px">ResourceCursorAdapter</span><span style="color:#003366; line-height:25px">)。</span><br style="line-height:25px"> 更多请参考《<strong><a title="阅读全文" target="_blank" href="http://hubingforever.blog.163.com/blog/static/17104057920105214038479/" style="color:rgb(207,121,28); line-height:25px; text-decoration:none">CursorAdapter</a></strong>》<br style="line-height:25px"><span style="line-height:25px">七、ResourceCursorAdapter</span><br style="line-height:25px"><span style="color:#003366; line-height:25px"></span><span style="color:#ff00ff; line-height:25px">ResourceCursorAdapter</span><span style="color:#003366; line-height:25px">是个虚类,它继承于</span><span style="color:#ff6600; line-height:25px">CursorAdapter</span><span style="color:#003366; line-height:25px">。<br style="line-height:25px"> 它实现了</span><span style="color:#0000ff; line-height:25px">newView</span><span style="color:#003366; line-height:25px">,但仍然没有实现</span><span style="color:#0000ff; line-height:25px">bindView</span><span style="color:#003366; line-height:25px"><br style="line-height:25px"> 直接子类只有</span><span style="color:#993300; line-height:25px">SimpleCursorAdapter</span><span style="color:#003366; line-height:25px">,无间接子类。</span><br style="line-height:25px"> 更多请参考《<strong><a title="阅读全文" target="_blank" href="http://hubingforever.blog.163.com/blog/static/17104057920105242555625/" style="color:rgb(207,121,28); line-height:25px; text-decoration:none">ResourceCursorAdapter</a></strong>》<br style="line-height:25px"><span style="line-height:25px">八、SimpleCursorAdapter</span><br style="line-height:25px"><span style="color:#ff00ff; line-height:25px">SimpleCursorAdapter</span><span style="color:#003366; line-height:25px">继承于</span><span style="color:#ff6600; line-height:25px">CursorAdapter</span><span style="color:#003366; line-height:25px">。它不是虚类,已经实现了</span><span style="color:#0000ff; line-height:25px">bindView</span><span style="color:#003366; line-height:25px">。</span><br style="line-height:25px"> 更多请参考《<strong><a title="阅读全文" target="_blank" href="http://hubingforever.blog.163.com/blog/static/1710405792010431621954/" style="color:rgb(207,121,28); line-height:25px; text-decoration:none">SimpleCursorAdapter</a></strong>》</div> <div style="line-height:25px"> <span style="line-height:25px">九、WrapperListAdapter</span><br style="line-height:25px"><span style="color:#003366; line-height:25px"></span><span style="color:#ff00ff; line-height:25px">WrapperListAdapter</span><span style="color:#003366; line-height:25px">扩展了</span><span style="color:#ff6600; line-height:25px">ListAdapter</span><span style="color:#003366; line-height:25px">接口<br style="line-height:25px"> 实现了</span><span style="color:#993300; line-height:25px">WrapperListAdapter</span><span style="color:#003366; line-height:25px">接口的类只有:</span><span style="color:#ff9900; line-height:25px">HeaderViewListAdapter</span><br style="line-height:25px"><span style="color:#003366; line-height:25px"></span><span style="color:#ff00ff; line-height:25px">WrapperListAdapter</span><span style="color:#003366; line-height:25px">只声明了一个方法:</span><br style="line-height:25px"><span style="color:#003366; line-height:25px"></span><span style="color:#0000ff; line-height:25px">publicabstractListAdaptergetWrappedAdapter()</span><br style="line-height:25px"><span style="line-height:25px">十、HeaderViewListAdapter</span><br style="line-height:25px"><span style="color:#ff00ff; line-height:25px">HeaderViewListAdapter</span><span style="color:#003366; line-height:25px">实现了WrapperListAdapter接口,并实现了getWrappedAdapter方法。</span><br style="line-height:25px"> 更多请参考《<strong><a title="阅读全文" target="_blank" href="http://hubingforever.blog.163.com/blog/static/17104057920105271412200/" style="color:rgb(207,121,28); line-height:25px; text-decoration:none">HeaderViewListAdapter</a></strong>》</div> </wbr></wbr></wbr></wbr></wbr></wbr>
评论这张
转发至微博
分享到:
评论
1 楼 sixinya 2013-12-24  
..........................................................................................................................................................................................

相关推荐

Global site tag (gtag.js) - Google Analytics