问题描述
我写的ListView自定义适配器延伸BaseAdapter,在这种方法
I am writing a custom adapter for ListView which extends BaseAdapter and in this method
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View vi = convertView;
if (vi == null)
vi = inflater.inflate(R.layout.x, null);
}
为什么是检查如果(六== NULL)
执行。 getView()
被称为为行,当谈到在屏幕的可见区域。因此,六
将空
每次 getview()
被称为?那么,为什么是必要的检查在这里?
why is the check if(vi==null)
performed. getView()
is called for row when it comes in the visible area of the screen. So vi
will be null
everytime getview()
is called? So why is the check necessary here.?
P.S。我于着色列表视图中某些特定行得到了一些问题,但是当我删除此检查,一切正常。这就是为什么我想知道在它的有用性。
P.S. I was getting some problem on coloring some specific rows of the listview, but when i removed this check, everything works fine. Thats why i am wondering over its usefullness.
推荐答案
的 convertView
参数的可以是一个循环视图(例如,后向下滚动,前行变得看不见的,所以他们的查看
对象不被破坏,但回收和再利用参数)通过。
The convertView
parameter may be a recycled view (for example, after scrolling down, the top rows become invisible, so their View
objects are not destroyed, but recycled and passed as parameters for reuse).
然而,第一次的拉伸请求时,不存在图(例如,与该列表屏幕加载第一次)。因此,在这种情况下, convertView
是没有价值的,因为什么也没有回收(这是空
),在这种情况下,你必须使用充气创建的行
However, the very first time a draw request comes, there is no view (e.g. the first time the screen with the list is loaded). Hence, in this case convertView
has no value because nothing has been recycled (it is null
), in which case you must create the rows using the inflater.
这篇关于在CustomAdapters状态,如果(查看== NULL)使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!