本文介绍了如果在Android的适配器是静态内部类和非静态内部类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个活动一个ListView和我设置自定义适配器到ListView。

I have a ListView in an Activity and I am setting a custom adapter to the ListView.

如果我的适配器类是:

private static class MyAdapter extends ArrayAdapter

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.

推荐答案

握住上下文是从罚款,如果你小心你如何使用适配器适配器之内。适配器通常依赖于它们的上下文(一个Activity)的生命周期,所以它的罚款。使用WeakReference的,只有当它是有道理的。

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.

这篇关于如果在Android的适配器是静态内部类和非静态内部类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 20:49