• Andriod中的数据绑定 :SimpleCursorAdapter篇


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

      Since: API Level 11

    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 CursorAdapter(Context, Cursor, int).

    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 view, Cursor cursor, int columnIndex)
      Since: API Level 1

    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 view, Context context, Cursor cursor)

      Since: API Level 1

    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 SimpleCursorAdapter.ViewBinder is available, setViewValue(android.view.View, android.database.Cursor, int) 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, setViewText(TextView, String) is invoked. If the returned value is false and the view to bind is an ImageView, setViewImage(ImageView, String) is invoked. If no appropriate binding can be found, an IllegalStateException 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
    IllegalStateExceptionif binding cannot occur
    做个快乐的自己。
  • 相关阅读:
    【bzoj2653】【middle】【主席树+二分答案】
    Codeforces 464E. The Classic Problem
    关于主席树的入门,讲解和题单
    BZOJ3531-[Sdoi2014]旅行(树剖+线段树动态开点)
    [bzoj3123][洛谷P3302] [SDOI2013]森林(树上主席树+启发式合并)
    1018_两个圆相交的面积
    String对象中常用的方法
    张爱玲写的信
    React Native拆包及热更新方案 · Solartisan
    vue项目实战
  • 原文地址:https://www.cnblogs.com/Jessy/p/2336535.html
Copyright © 2020-2023  润新知