successfully posted Runnable only gets executed when parent is invalidated

梦想的初衷 提交于 2019-12-09 23:27:09

问题


I sometimes run into the following scenario :

  • I call View.post(Runnable r) and it returns true
  • when calling android.os.Looper.myLooper().dump(...), the runnable seems not in the messageQueue
  • after calling invalidate on the main layout (for example after 20 seconds), the Runnable gets executed

This only happens from time to time, it happens on multiple devices and on multiple Android versions.

The problem seems similar to Runnable is posted successfully but not run and Android: Button within ListView not receiving onClick events

Can somebody explain under which circumstances a Runnable gets posted but doesn't get executed (yet)? And why it does get executed after a (parent) invalidate.

Note: Posting the Runnable using runOnUiThread works fine but I can't use this: my real problem is that sometimes the OnClickListener is not called; this was tracked down to the call to post(performClick) in View.onTouchEvent.

I assume my View hierarchy is in some weird state but I'm clueless.
My Views are created in code and roughly consists of

  • RelativeLayout
  • ListView
  • HorizontalListView (from http://www.dev-smart.com/archives/34)
  • MyOwnView

回答1:


The answer is given here ListView.hasWindowFocus==true but child views hasWindowFocus==false

ListView doesn't like an adapter of Views.



来源:https://stackoverflow.com/questions/11242226/successfully-posted-runnable-only-gets-executed-when-parent-is-invalidated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!