2015-12-23 11 views
0

Android官方文档说以下内容:使用from`的困惑``和Android中SimpleAdapter类to` PARAMS

final String[] from = new String[] {"TEXT1", "TEXT2"}; 
final int[] to = new int[] {android.R.id.text1, android.R.id.text2}; 
a = new SimpleAdapter(this, list, resource, from, to) 

我:

from A list of column names that will be added to the Map associated with each item. 
to  The views that should display column in the "from" parameter. These should all be TextViews. The first N views in this list are given the values of the first N columns in the from parameter. 

如下我已经做到了这一点能够在视图中设置数据就好了,但我很困惑,为什么from参数是必要的。为什么不只是提供一个XML资源列表?为什么还需要传入(列名?)列表?

请帮我理解。

回答

0

该列表中的前N个视图被赋予from参数中前N列的值。

这意味着在from参数的值将在to参数相应的视图来设置。根据SimpleAdapter Android docs,如果视图是TextView s,则预计将列出String s,并且将通过呼叫setViewText(TextView, String)绑定到TextView s。