为什么我们需要ArrayAdapter <t>中的Context参数(context,resId,T []对象)?

时间:2015-06-23 23:36:01

标签: android

我已经搜索了堆栈溢出和谷歌。但无法弄清楚为什么我们需要传递Context参数?    所有ArrayAdapter必须做的是,采用布局resId从这里的数据集“objects”参数返回我们想要的视图。

2 个答案:

答案 0 :(得分:2)

Context用于get a reference to the LayoutInflater (retrieved through getSystemService)ArrayAdapter需要使用UILabel将提供的布局资源扩展到一个视图中,该视图可以填充传入的项目。

答案 1 :(得分:1)

Context用于在ArrayAdapter中创建mInflater。 你可以在这里看到源代码。 http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.0_r1/android/widget/ArrayAdapter.java#ArrayAdapter.0mInflater

    private void More ...init(Context context, int resource, int textViewResourceId, List<T> objects) {
270        mContext = context;
271        mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
272        mResource = mDropDownResource = resource;
273        mObjects = objects;
274        mFieldId = textViewResourceId;
275    }