java-在Android中管理View重用的代码在哪里?

java-在Android中管理View重用的代码在哪里?,第1张

概述在Android中管理View重用的源代码在哪里?我可以想到此过程的三个不同部分,但可能还有更多:>确定视图是否符合重用条件的逻辑>管理可重复使用的视图池的代码>从池中删除可重复使用的View并重置其属性值以表示逻辑上不同的View的代码编辑:博客文章DevelopingapplicationsforAndroi

在Android中管理VIEw重用的源代码在哪里?我可以想到此过程的三个不同部分,但可能还有更多:

>确定视图是否符合重用条件的逻辑
>管理可重复使用的视图池的代码
>从池中删除可重复使用的VIEw并重置其属性值以表示逻辑上不同的VIEw的代码

编辑:博客文章Developing applications for Android – gotchas and quirks给出了以下示例:

public class PencilWise extends ListActivity {    VIEw activeElement;    // ...    @OverrIDe    public voID onCreate ( Bundle savedInstanceState ) {        // ...        this.getListVIEw( ).setonItemClickListener ( new OnItemClickListener ( ) {            public voID onItemClick ( AdapterVIEw<?> parent, VIEw vIEw, int position, long ID ) {                MyActivity.this.activeElement = vIEw;                MyActivity.this.showDialog ( DIALOG_ANSWER );            }        } );    }}

The showDialog method will display the answer dialog, which needs to kNow what question the user has opened. The problem is that by the time the dialog opens, the vIEw passed to onItemClick might have been reused, and so activeElement would no longer point to the element the user clicked to open the dialog in the first place!

解决方法:

我认为您正在寻找的一个很好的例子是在Widget包中的AbsListVIEw.RecycleBin内部类中.
您可以在此处在线查看代码:
https://android.googlesource.com/platform/frameworks/base/+/android-2.2_r1.1/core/java/android/widget/AbsListView.java#3888

以下是文档摘录:

The RecycleBin facilitates reuse of vIEws across layouts. The RecycleBin has two levels of
storage: ActiveVIEws and ScrapVIEws. ActiveVIEws are those vIEws which were onscreen at the
start of a layout. By construction, they are displaying current information. At the end of
layout, all vIEws in ActiveVIEws are demoted to ScrapVIEws. ScrapVIEws are old vIEws that
Could potentially be used by the adapter to avoID allocating vIEws unnecessarily.

总结

以上是内存溢出为你收集整理的java-在Android中管理View重用的代码在哪里?全部内容,希望文章能够帮你解决java-在Android中管理View重用的代码在哪里?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1210478.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-04
下一篇2022-06-04

发表评论

登录后才能评论

评论列表(0条)

    保存