博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Andriod中的数据绑定 :SimpleCursorAdapter篇
阅读量:5321 次
发布时间:2019-06-14

本文共 3074 字,大约阅读时间需要 10 分钟。

public                                                   SimpleCursorAdapter( context, int layout, c, from, int[] to, int flags)

  Since:

Standard constructor.

Parameters
context          The context where the ListView associated with this SimpleListItemFactory is running
layout          resource identifier of a layout file that defines the views for this list item. The layout file should include at least those named views defined in "to"
c          The database cursor.  Can be null if the cursor is not available yet.
from          A list of column names representing the data to bind to the UI.  Can be null             if the cursor is not available yet.
to          The views that should display column in the "from" parameter.            These should all be TextViews. The first N views in this list            are given the values of the first N columns in the from            parameter.  Can be null if the cursor is not available yet.
flags          Flags used to determine the behavior of the adapter, as per .

 

SimpleCursorAdapter.ViewBinder

 This class can be used by external clients of SimpleCursorAdapter to bind values fom the Cursor to views. You should use this class to bind values from the Cursor to views that are not directly supported by SimpleCursorAdapter or to change the way binding occurs for views supported by SimpleCursorAdapter.

 

public                           abstract                  boolean     
setViewValue
( view, cursor, int columnIndex)
  Since:

Binds the Cursor column defined by the specified index to the specified view. When binding is handled by this ViewBinder, this method must return true. If this method returns false, SimpleCursorAdapter will attempts to handle the binding on its own.

Parameters
view          the view to bind the data to
cursor          the cursor to get the data from
columnIndex          the column at which the data can be found in the cursor
Returns
  • true if the data was bound to the view, false otherwise

 

Cursor要实现AbstractCursor

public 
boolean setViewValue(View view, Cursor cursor, 
int columnIndex)
    {
        MyCursor = (MyCursor) cursor;
        MyFavorite fav = cur.getBean();       
        
        
        
switch (view.getId())
    {
        
case R.id.A_name:
            TextView nView = (TextView) view;            
                String name = fav.getName()
                nView.setText(name);
       
case R.id.B_name:
       ImageView imageView = (ImageView) view;
       imageView.setVisibility(View.VISIBLE);
       imageView.setImageResource(R.drawable.icon1)
    ....   
        
    
            
       
        
     }        
        Return 
true
    
    }

 

Public Methods

        public                                             void      bindView( view, context, cursor)

  Since:

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. Binding occurs in two phases. First, if a is available, is invoked. If the returned value is true, binding has occured. If the returned value is false and the view to bind is a TextView, is invoked. If the returned value is false and the view to bind is an ImageView, is invoked. If no appropriate binding can be found, an is thrown.

Parameters
view          Existing view, returned earlier by newView
context          Interface to application's global information
cursor          The cursor from which to get the data. The cursor is already moved to the correct position.
Throws
if binding cannot occur
See Also

转载于:https://www.cnblogs.com/Jessy/archive/2012/02/03/2336535.html

你可能感兴趣的文章
Could not resolve view with name '***' in servlet with name 'dispatcher'
查看>>
[转载] redis 的两种持久化方式及原理
查看>>
C++ 删除字符串的两种实现方式
查看>>
MyBaits学习
查看>>
管道,数据共享,进程池
查看>>
[Cypress] Stub a Post Request for Successful Form Submission with Cypress
查看>>
SDUTOJ3754_黑白棋(纯模拟)
查看>>
php中的isset和empty的用法区别
查看>>
Android ViewPager 动画效果
查看>>
把word文档中的所有图片导出
查看>>
ubuntu 18.04取消自动锁屏以及设置键盘快捷锁屏
查看>>
Leetcode 589. N-ary Tree Preorder Traversal
查看>>
正则表达式
查看>>
arcgis api 4.x for js 结合 Echarts4 实现散点图效果(附源码下载)
查看>>
YTU 2625: B 构造函数和析构函数
查看>>
apache自带压力测试工具ab的使用及解析
查看>>
jenkins搭建
查看>>
加固linux
查看>>
IPSP问题
查看>>
10.17动手动脑
查看>>