什么是更好的方式,保持适配器作为一个内部类的活动或外部的? [英] What is the better way, keeping adapter as an inner class of activity or outside?

查看:165
本文介绍了什么是更好的方式,保持适配器作为一个内部类的活动或外部的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要检查的更好更快地使用适配器一个ListView的计划。是它还是活动课?

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

推荐答案

这更多的是比Android一个Java的问题。

This is more of a Java question than Android.

内部类多为使您的code可读的,当你使用静态内部类不影响性能的长。静态内部类拉出编译器和编译为单独的类(类$将InnerClass)。

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).

因此​​,如果采用内部类是帮助你在code组织方面,你可以放心地继续使用它们。虽然我强烈建议使用静态内部类。

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.

修改

静态内部类在这样的背景下,这是一种将不需要访问任何活动的变量的适配器足够了。

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.

这篇关于什么是更好的方式,保持适配器作为一个内部类的活动或外部的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆