简体   繁体   中英

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM