将适配器保留为活动的内部类还是外部类,更好的方法是什么?
我想检查使用 ListView 适配器的程序的更好更快的方法。是在外面还是在活动课上?
I want to check the better and faster way for program of using adapter for a ListView. Is it out or in activity class?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这更像是一个 Java 问题,而不是 Android 问题。
内部类更多的是为了使代码可读,并且只要使用静态内部类就不会影响性能。静态内部类由编译器拉出并编译为单独的类(Class$InnerClass)。
因此,如果使用内部类对您的代码组织有帮助,您可以放心地继续使用它们。尽管我强烈建议使用静态内部类。
编辑
在此上下文中,静态内部类就足够了,它是一个适配器,不需要访问活动的任何变量。
This is more of a Java question than Android.
Inner classes are more for making your code readable and do not affect performance as long as you use static inner classes. Static inner classes are pulled out by the compiler and compiled as separate classes (Class$InnerClass).
So if using inner classes are helpful to you in terms of code organization, you can safely go ahead and use them. Though I'd strongly recommend using static inner classes.
Edit
Static inner classes suffice in this context, which is of an adapter which wouldn't need access to any of the variables of the Activity.