{"id":1263,"date":"2023-03-18T09:53:20","date_gmt":"2023-03-18T01:53:20","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1263"},"modified":"2023-04-29T09:25:40","modified_gmt":"2023-04-29T01:25:40","slug":"efficient-implementation-of-countdown-for-all-items-in-android-recycleview","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/18\/efficient-implementation-of-countdown-for-all-items-in-android-recycleview\/","title":{"rendered":"Android RecycleView\u5168\u90e8item\u5012\u8ba1\u65f6\u7684\u9ad8\u6548\u5b9e\u73b0"},"content":{"rendered":"<p>\u9700\u8981\u4f7f\u7528\u5168\u5c40\u7684\u5b9a\u65f6\u5668\uff0c\u800c\u4e0d\u662f\u6bcf\u6761item\u5747\u8bbe\u7f6e\u5b9a\u65f6\u5668\uff0c\u800c\u4e14\u5728\u53ef\u89c1\u89c6\u56fe\u5185\u5b9a\u65f6\u5237\u65b0UI<\/p>\n<p><!-- more --><\/p>\n<pre><code class=\"language-java\">public void initTimer() {\n    mTimer = new Timer();\n    TimerTask timerTask = new TimerTask() {\n        @Override\n        public void run() {\n            onDownTimeTask();\n        }\n    };\n    mTimer.schedule(timerTask, 0, 1000);\n}\n\nprivate void onDownTimeTask() {\n    if (mBargainOrderList != null &amp;&amp; mBargainOrderList.size() &gt; 0) {\n        int firstVisiblePosition = mLayoutManager.findFirstVisibleItemPosition();\n        int lastVisiblePosition = mLayoutManager.findLastVisibleItemPosition();\n        for (int i = 0; i &lt; mBargainOrderList.size(); i++) {\n            if (i &gt;= firstVisiblePosition &amp;&amp; i &lt;= lastVisiblePosition) {\n                final BargainOrderAdapter.ViewHolder viewHolder = (BargainOrderAdapter.ViewHolder) mMyBargainOrderListRecyclerView.findViewHolderForLayoutPosition(i);\n                mActivity.runOnUiThread(new Runnable() {\n                    @Override\n                    public void run() {\n                        viewHolder.bargainCountdownView.refresh();\n                    }\n                });\n            }\n        }\n    }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9700\u8981\u4f7f\u7528\u5168\u5c40\u7684\u5b9a\u65f6\u5668\uff0c\u800c\u4e0d\u662f\u6bcf\u6761item\u5747\u8bbe\u7f6e\u5b9a\u65f6\u5668\uff0c\u800c\u4e14\u5728\u53ef\u89c1\u89c6\u56fe\u5185\u5b9a\u65f6\u5237\u65b0UI public void i [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[119],"tags":[315],"class_list":["post-1263","post","type-post","status-publish","format-standard","hentry","category-android-ui","tag-recycleview"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1263","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1263"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1263\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}