问题
I have a ListView in an Activity and I am setting a custom adapter to the ListView.
Should my adapter class be:
private static class MyAdapter extends ArrayAdapter
or
private class MyAdapter extends ArrayAdapter
I guess it should make no difference as long as the adapter is enclosed within the activity reference but wanted to confirm that.
回答1:
Holding onto the context is fine from within an adapter if you are careful about how you use the adapter. Adapters are usually tied to the lifecycle of their Context (an Activity) so it's fine. Use a WeakReference only if it makes sense.
来源:https://stackoverflow.com/questions/7924834/should-adapters-in-android-be-static-inner-classes-or-non-static-inner-classes