Reputation: 3661
Hi I have a question about using private class in Android activities. Let's say I have a simple listView in an activity. I want to define an adapter class for this listView(which extends BaseAdapter). Since the adapter is pretty simple, I want to define a private class in this Activity class. My question is this. Is it okay to define this private class non statically? Or is it better practice to define it statically?
If I have to define it statically, I have to pass an object (say List) to this private adapter's constructor then assign this to its member variable in it. If I define it non statically, I can define List object in Activity class and use it within the private adapter.
Is this okay? Thanks
Upvotes: 1
Views: 2682
Reputation: 4835
Using static variables or classes
makes most times only sence if you want to use the object in another class.
Since you want to declare your adapter as inner-class inside your activity and declare it private
it does not make any sense to declare your class as static
.
If you want to be able to have access to your adapter from an outer-class it might make sense to declare it static, it depends on what you want to do, but
static variables as well as classes should always be declared as public
Upvotes: 2