What is the better way, keeping adapter as an inner class of activity or outside?

ぃ、小莉子 提交于 2019-12-23 10:09:42

问题


I want to check the better and faster way for program of using adapter for a ListView. Is it out or in activity class?


回答1:


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.



来源:https://stackoverflow.com/questions/8904038/what-is-the-better-way-keeping-adapter-as-an-inner-class-of-activity-or-outside

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