public abstract class SimpleCursorTreeAdapter extends ResourceCursorTreeAdapter
java.lang.Object
android.widget.BaseExpandableListAdapter
android.widget.CursorTreeAdapter
android.widget.ResourceCusorTreeAdapter
android.widget.SimpleCursorTreeAdapter
这是一个用起来很方便的适配器类,它主要将Cursor与在XML文件中定义的TextView或ImageView进行映射。比如,你想设定要展示三列,那么当做好绑定之后,视图就会展示你设定好的那些列;当然了,视图的外观是定义在XML文件里面的,你只需用这个类与视图做好绑定就可以了。(译者注:Android推荐我们尽可能的将组视图和子视图分离开,也就是说不要把整体定义在一个布局文件当中。)与视图绑定有两个阶段。
第一阶段:如果使用SimpleCursorTreeAdapter.ViewBinder时,那么就会调用setViewValue(android.view.View, android.database.Cursor, int)方法。该方法返回true就说明绑定成功,否则返回false,这就到了第二阶段,SimpleCursorAdapter内部开始自行绑定,过程是这样的,若绑定到TextView上,调用setViewText(TextView, String);若绑定到ImageView上,调用setViewImage(ImageView, String),如果视图不是TextView或ImageView则抛出IllegalStateException异常。
public interface SimpleCursorTreeAdapter.ViewBinder
这个内部接口可以在外部通过SimpleCursorTreeAdapter.ViewBinder的方式进行 Cursor与View的绑定。
public SimpleCursorTreeAdapter (Context context, Cursor cursor, int collapsedGroupLayout, int expandedGroupLayout, String[] groupFrom, int[] groupTo, int childLayout, int lastChildLayout, String[] childFrom, int[] childTo)
public SimpleCursorTreeAdapter (Context context, Cursor cursor, int collapsedGroupLayout, int expandedGroupLayout, String[] groupFrom, int[] groupTo, int childLayout, String[] childFrom, int[] childTo)
该构造函数只是少了一个参数lastChildLayout
public SimpleCursorTreeAdapter (Context context, Cursor cursor, int groupLayout, String[] groupFrom, int[] groupTo, int childLayout, String[] childFrom, int[] childTo)
public SimpleCursorAdapter.ViewBinder getViewBinder ()
返回SimpleCursorTreeAdapter.ViewBinder引用,这个ViewBinder用来将数据绑定到 视图上的。
返回值
如果ViewBinder不存在,则返回null。
参考
setViewBinder(android.widget.SimpleCursorTreeAdapter.ViewBinder)
public void setViewBinder (SimpleCursorTreeAdapter.ViewBinder viewBinder)
. 设置视图绑定器。
参数
参考
getViewBinder()
public void setViewText (TextView v, String text)
仅当ViewBinder不存在或是当ViewBinder不为TextView绑定时(也就是setViewValue()返回false),则这个方法会被bindView()调用,以便为TextView设置文本。可重写适配器从数据库中检索过滤字符串。
参数
protected void bindChildView (View view, Context context, Cursor cursor, boolean isExpanded)
通过参数cursor将数据绑定到已有的子视图上。。
参数
protected void bindGroupView (View view, Context context, Cursor cursor, boolean isExpanded)
通过参数cursor将数据绑定到已有组视图上。
参数
protected void setViewImage (ImageView v, String value)
这个方法会被bindView()调用,以便为ImageView设置图片。默认情况下,参数value作为图片资源ID来看待,否则会视为图片的Uri。 另外还可以通过过滤器来获得更灵活的设置。
参数