什么是更好的方式,保持适配器作为一个内部类的活动或外部的?部类、作为一个、适配器、方式

2023-09-12 23:45:22 作者:镜中花水中月

我要检查的更好更快地使用适配器一个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?

推荐答案

这更多的是比Android一个Java的问题。

This is more of a Java question than Android.

内部类多为使您的code可读的,当你使用静态内部类不影响性能的长。静态内部类拉出编译器和编译为单独的类(类$将InnerClass)。

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).

因此​​,如果采用内部类是帮助你在code组织方面,你可以放心地继续使用它们。虽然我强烈建议使用静态内部类。

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.

修改的

静态内部类在这样的背景下,这是一种将不需要访问任何活动的变量的适配器足够了。

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.