SimpleCursorAdapter继承于ResourceCursorAdapter。
构造函数如下:
| Public Constructors | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| <nobr style="line-height:21px"></nobr> | <nobr style="line-height:21px"><span style="line-height:21px; margin-right:2px"><a rel="nofollow" href="http://developer.android.com/reference/android/widget/SimpleCursorAdapter.html#SimpleCursorAdapter(android.content.Context,%20int,%20android.database.Cursor,%20java.lang.String%5B%5D,%20int%5B%5D)" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">SimpleCursorAdapter</a></span>(<a rel="nofollow" href="http://developer.android.com/reference/android/content/Context.html" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">Context</a>context, int layout,<a rel="nofollow" href="http://developer.android.com/reference/android/database/Cursor.html" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">Cursor</a>c,<a rel="nofollow" href="http://developer.android.com/reference/java/lang/String.html" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">String[]</a>from, int[] to)</nobr>
This constructor is deprecated. This option is discouraged, as it results in Cursor queries being performed on the application's UI thread and thus can cause poor responsiveness or even Application Not Responding errors. As an alternative, use LoaderManagerwith aCursorLoader.
| ||||||||||
| <nobr style="line-height:21px"></nobr> | <nobr style="line-height:21px"><span style="line-height:21px; margin-right:2px"><a rel="nofollow" href="http://developer.android.com/reference/android/widget/SimpleCursorAdapter.html#SimpleCursorAdapter(android.content.Context,%20int,%20android.database.Cursor,%20java.lang.String%5B%5D,%20int%5B%5D,%20int)" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">SimpleCursorAdapter</a></span>(<a rel="nofollow" href="http://developer.android.com/reference/android/content/Context.html" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">Context</a>context, int layout,<a rel="nofollow" href="http://developer.android.com/reference/android/database/Cursor.html" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">Cursor</a>c,<a rel="nofollow" href="http://developer.android.com/reference/java/lang/String.html" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">String[]</a>from, int[] to, int flags)</nobr>
Standard constructor.
| ||||||||||
SimpleCursorAdapter实现了ResourceCursorAdapter的bindView方法
<wbr style="line-height:25px">bindview方法用于实现数据和view的绑定。<br style="line-height:25px"><wbr style="line-height:25px"><span style="color:#993300; line-height:25px">SimpleCursorAdapter</span><span style="color:#003366; line-height:25px">允许你绑定一个游标的列到ListView上,并使用自定义的layout显示每个项目。</span><br style="line-height:25px"><span style="color:#993300; line-height:25px">SimpleCursorAdapter</span><span style="color:#003366; line-height:25px">的创建,需要传入当前的上下文、一个layout资源,一个游标和两个数组:<br style="line-height:25px"> 前一个数组表示要显示游标中哪些列,另一个(相同大小)数组包含View中的资源ID,用于控制游标中相应列的数据的显示。</span><wbr style="line-height:25px"><br style="line-height:25px"> 下面的框架代码显示了如何构造一个SimpleCursorAdapter来显示联系人信息:<br style="line-height:25px"><span style="color:#3366ff; line-height:25px">StringuriString=“content://contacts/people/”;</span><br style="line-height:25px"><span style="color:#3366ff; line-height:25px">CursormyCursor=managedQuery(Uri.parse(uriString),null,null,null,null);</span><br style="line-height:25px"><span style="color:#3366ff; line-height:25px">String[]fromColumns=newString[]{People.NUMBER,People.NAME};</span><br style="line-height:25px"><span style="color:#3366ff; line-height:25px">int[]toLayoutIDs=newint[]{R.id.nameTextView,R.id.numberTextView};</span><br style="line-height:25px"><span style="color:#3366ff; line-height:25px">SimpleCursorAdaptermyAdapter;</span><br style="line-height:25px"><span style="color:#0000ff; line-height:25px">myAdapter=newSimpleCursorAdapter(this,R.layout.simplecursorlayout,myCursor,fromColumns,toLayoutIDs);</span><br style="line-height:25px"><span style="color:#3366ff; line-height:25px">myListView.setAdapter(myAdapter);</span><br style="line-height:25px"><wbr style="line-height:25px">关于SimpleCursorAdapter的更多内容请参考《<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>》,《<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>》</wbr></wbr></wbr></wbr>
| <nobr style="line-height:21px">void</nobr> | <nobr style="line-height:21px"><span style="line-height:21px; margin-right:2px"><a rel="nofollow" href="http://developer.android.com/reference/android/widget/SimpleCursorAdapter.html#bindView(android.view.View,%20android.content.Context,%20android.database.Cursor)" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">bindView</a></span>(<a rel="nofollow" href="http://developer.android.com/reference/android/view/View.html" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">View</a>view,<a rel="nofollow" href="http://developer.android.com/reference/android/content/Context.html" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">Context</a>context,<a rel="nofollow" href="http://developer.android.com/reference/android/database/Cursor.html" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">Cursor</a>cursor)</nobr>
Binds all of the field names passed into the "to" parameter of the constructor with their corresponding cursor columns as specified in the "from" parameter.
|
本文深入探讨了SimpleCursorAdapter在Android开发中的角色,包括其构造函数、bindView方法以及实例化过程。通过具体代码示例展示了如何利用SimpleCursorAdapter将游标数据与自定义布局关联,以实现高效的数据展示。
180

被折叠的 条评论
为什么被折叠?



