Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 616
hexin Avatar asked Jan 18 '12 01:01

hexin


1 Answers

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.

like image 118
Vikram Bodicherla Avatar answered Nov 08 '22 11:11

Vikram Bodicherla