问题描述
我想做一个ArrayAdapter
以显示图像和文本.如果可能的话,我不要例子.我希望有人向我解释getView()
的工作方式.
I want to do an ArrayAdapter
to display an image and text. I don't want examples if possible. I'd like someone to explain me how getView()
works.
谢谢.
推荐答案
getView()
是适配器的主要部分.它返回View
,它将显示为您的列表/网格/库/使用适配器项的任何视图.滚动视图(例如列表)时触发.
getView()
is the main part of your adapter. It returns View
that will be displayed as your list/grid/gallary/any view that use adapter item. It triggers when you scroll the view(list for example).
因此,您应该做的第一件事就是创建自定义适配器.您可以从BaseAdapter
扩展它.然后,您需要创建一些数据以显示(或将其从外部传递到适配器-这是更好的解决方案).
So the first thing you should do its to create your custom adapter. You may extend it from BaseAdapter
. Then you need to create some data to display (or pass it to adapter from out side - its better solution).
在此之后,重写getView()
方法,并确保在此处返回自定义视图.在您的情况下,它应该是带有ImageView
和TextView
的Layout
(并且不要忘记填写它们).
After that override getView()
method and make sure to return your custom View there. In your case it should be a Layout
with ImageView
and TextView
(and dont forget to fill them).
您可以从中了解更多信息:
You can learn more from :
- http://www.youtube.com/watch?v=N6YdwzAvwOA
- http://www.edureka.in/blog/what-are-adapters-在Android/
- http://lucasr.org/2012/04/05/performance- tips-for-androids-listview/
- http://www.youtube.com/watch?v=N6YdwzAvwOA
- http://www.edureka.in/blog/what-are-adapters-in-android/
- http://lucasr.org/2012/04/05/performance-tips-for-androids-listview/
这篇关于ArrayAdapter的getView()方法如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!