ListView.hasWindowFocus ==真实的,但孩子的意见hasWindowFocus ==假 [英] ListView.hasWindowFocus==true but child views hasWindowFocus==false

查看:928
本文介绍了ListView.hasWindowFocus ==真实的,但孩子的意见hasWindowFocus ==假的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时候,我注意到,对于一个视图V

Sometimes I notice that, for a View v

 - v.hasWindowFocus()==false
 - ((View)v.getParent()).hasWindowFocus())==true

如果我理解正确的文档,这不应该是这样的。

If I understand the docs correctly, this should never be the case.

v.getParent()是一个(子类)的ListView

v.getParent() is a (subclass) of ListView

这是什么可能导致此任何想法?

Any ideas on what might be causing this?

注:我认为这hasWindowFocus失配是根本原因<一href="http://stackoverflow.com/questions/11242226/successfully-posted-runnable-only-gets-executed-when-parent-is-invalidated">this问题

Note: I assume this hasWindowFocus-mismatch is the root cause for this issue

推荐答案

主要的原因是,ListView控件不喜欢适配器有意见的数组。

The main reason is that ListView doesn't like an adapter having an array of views.

所以,问题是由code触发像

So the problem is triggered by code like

public View getView (int position, View convertView, ViewGroup parent)
{
    return _views[position];
}

当在ListView的code看(或者更确切地说,它的父母AbsListView.obtainView方法),你会看到code像

When looking at the ListView code (or rather it's parents AbsListView.obtainView method) you'll see code like

    if (scrapView != null) {
        ...
        child = mAdapter.getView(position, scrapView, this);
        ...
        if (child != scrapView) {
            mRecycler.addScrapView(scrapView);

这可能发生 getView(位置,...)被调用scrapView!= _views [位置],因此scrapView将被回收利用。另一方面,这是很可能的是,同样的观点也再次加入的ListView,导致次越来越怪异状态。

It can happen that getView(position,...) is called with scrapView != _views[position] and hence scrapView will be recycled. On the other hand, it is quite likely that the same view is also added again to ListView, resulting in views getting weird states.

这应该IMO固定的ListView。

This should be fixed in ListView IMO.

这篇关于ListView.hasWindowFocus ==真实的,但孩子的意见hasWindowFocus ==假的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆