理解BaseAdapters以及如何使用它们 [英] Understanding BaseAdapters and how to use them
问题描述
我试图建立一个图像的GridView布局,这涉及到从BaseAdapter类派生新类。我一直在使用网站上的developer.android.com教程,但是我还是不太明白是什么意思。可能有人请给我解释一下到底什么是BaseAdapter?我不明白的是Android开发者网站上提供的定义。
I'm trying to set up a an image GridView Layout, and this involves deriving a new class from the BaseAdapter class. I have been using the tutorial on the website developer.android.com, but I still don't quite understand what it means. Could someone please explain to me what exactly is a BaseAdapter? I don't understand the definition provided by the Android developers website.
感谢
推荐答案
这是适配器,用于将数据绑定到一个视图。请参见适配器视图:
An adapter is used to bind data to a view. See AdapterView:
一个AdapterView是 查看其子女通过适配器来决定。的
An AdapterView is a view whose children are determined by an Adapter.
若干布局视图从适配器视图类似的GridView,ListView控件和画廊派生。
Several layout views derive from AdapterView like GridView, ListView, and Gallery.
当然,您一般不使用适配器视图
和适配器
直接,而是使用或从一个派生他们的子类。适配器的子类可以补充说,改变如何,你应该将数据绑定到查看其他功能。
Of course, you generally don't use AdapterView
and Adapter
directly, but rather use or derive from one of their subclasses. The subclasses of Adapter may add additional functionality that change how to you should bind data to view.
BaseAdapter
是适配器接口,简化实施适配器的抽象基类。你可以实现你自己的,但该框架提供了一些pretty的灵活适配器了。一些受欢迎的适配器:
BaseAdapter
is an abstract base class for the Adaptor interface to simplify implementing adapters. You could implement your own, but the framework provides some pretty flexible adapters already. Some popular adapters are:
<一个href="http://developer.android.com/reference/android/widget/ArrayAdapter.html">ArrayAdapter,
- 数据数组绑定到一个视图
- 覆盖
getView()
膨胀,填充,并返回一个自定义视图给定索引到数组中。该getView()
方法包括通过convertView
参数有机会再利用的观点。
- binds an array of data to a view
- override
getView()
to inflate, populate, and return a custom view for the given index in the array. ThegetView()
method includes an opportunity reuse views via theconvertView
parameter.
<一个href="http://developer.android.com/reference/android/widget/CursorAdapter.html">CursorAdapter,
- 从游标(如数据库光标)将数据绑定到一个视图
- 抽象所以你不要直接使用它,使用一个子类或派生您自己的
- 实现抽象方法
NewView的()
膨胀,填充,并返回所需的视图当前光标所在位置,并实现抽象方法bindView
来填充,正在重用现有的视图。
- binds data from a cursor (like a database cursor) to a view
- abstract so you don't use it directly, use a subclass or derive your own
- implement the abstract method
newView()
to inflate, populate, and return the desired view for the current cursor position and implement the abstract methodbindView
to populate an existing view that is being reused..
<一个href="http://developer.android.com/reference/android/widget/SimpleCursorAdapter.html">SimpleCursorAdapter,
- 在一个具体的实施
的CursorAdapter
的
- 它可以采取一排布局和游标中的列映射到行布局部件
- 支持文本和图像,而且可以自定义使用
setViewText
和setViewImage
- 可以支持其他类型,并且可以通过一个钩子定义绑定:客户实施了
setViewValue()$ c中的
SimpleCursorAdapter.ViewBinder
接口$ C>办法膨胀,填充,并返回所需的视图用于给定的行(当前光标状态),数据栏。这种方法可以定义仅仅是特殊的意见和绑定,但还是推迟到SimpleCursorAdapter的为正常绑定标准行为。
- a concrete implementation of
CursorAdapter
- it can take a row layout and a mapping of cursor columns to row layout widgets
- supports text and images, but can customize using
setViewText
andsetViewImage
- can support other types and can customize bindings through a hook: clients implement the
SimpleCursorAdapter.ViewBinder
interface with asetViewValue()
method to inflate, populate, and return the desired view for a given row (current cursor state) and data "column". This method can define just the "special" views and bindings, but still defer to SimpleCursorAdapter's standard behavior for the "normal" bindings.
这篇关于理解BaseAdapters以及如何使用它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!