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
posted on 2012-02-03 09:31  higirle  阅读(973)  评论(0编辑  收藏  举报