Click events from views inside MergeAdapter items only fired after scrolling

徘徊边缘 提交于 2019-12-08 12:08:55

问题


I'm currently using cwac-merge in my app and I'm facing an issue.

So I have this listview with different parts. The first ones or static views added to the MergeAdapter. They are directly added without activating/deactivating them.

Then I'm adding other adapters to my MergeAdapter and hiding them straight away with setActive(). These are filled asynchronously but added before listView.setAdapter(adapter). So I'm doing this for each adapter:

  1. add the adapter to the MergeAdapter with adapter.addAdapter(subAdapter)
  2. hide it with adapter.setActive(subAdapter, false)
  3. when the data is fetch, add the retrieved items to the subAdapter, subAdapter.addItems(items) and then show the adapter with adapter.setActive(subAdapter, true)

Everything is working perfectly and my view is looking good except one thing. I've got a few buttons in the top views from the MergeAdapter. The click behaviour is wrong. Sometimes the click events get only fired after scrolling the ListView. I've noticed it only happen if I play with the setActive() function. If I comment every setActive() calls, the issue can't be reproduced. If I click multiple times then scroll, as many clicks are fired.

Here is some screenshots. The static views are the image and the view with the 4 buttons. Then the dynamic part is the adapters after (biography, last played on and best tracks)

UPDATE: I've managed to (sort of) fix it by calling subAdapter.notifyDatasetChanged() after activating each of them. It's still hacky and doesn't work every time.

UPDATE: I think this should be covered by the library given that:

Note, though, that you can modify the underlying adapters. So, for example, if you add a CursorAdapter to the MergeAdapter, and you requery() the Cursor, the changes should be reflected via the MergeAdapter to whatever AdapterView the MergeAdapter is connected to.


回答1:


The issue was actually specific to my project. While the content was being fetched and filled, I was showing a screen containing a ProgressBar over the hidden content. The moment when I was showing the content and the one when the data was retrieved were colliding. Technically, the setVisibility(VISIBLE) on the screen view was happening at a bad time with the mergeadapter.setActive() command.

Anyway, good times! Thanks @CommonsWare



来源:https://stackoverflow.com/questions/17467472/click-events-from-views-inside-mergeadapter-items-only-fired-after-scrolling

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