List<Map<String,Object>> data=new ArrayList<Map<String,Object>>(); String[] s=efoodname.split(" "); String[] s01=efoodinfo.split(" "); for(int i=0;i<s.length;i++){ Map<String,Object> map=new HashMap<String,Object>(); map.put("TextView04", s[i]); map.put("TextView05", s01[i]); data.add(map); } SimpleAdapter sa=new SimpleAdapter(this,data,R.layout.ex_foodinfo,new String[]{"TextView04","TextView05"},new int[]{R.id.TextView04,R.id.TextView05}); setListAdapter(sa);
關(guān)于Map<String,Object>的用法與作用:
java.util..put( key, value)
public abstract V put (K key, V value)
Maps the specified key to the specified value.(為被指定的鍵映射被指定的值,也就是說創(chuàng)建一個(gè)映射,即讓一個(gè)指定的鍵代表一個(gè)指定的值)
Parameters
| key |
the key. |
| value |
the value. |
Returns
- the value of any previous mapping with the specified key or
null if there was no mapping.(任何一個(gè)值映射到一個(gè)指定的鍵或者NULL(如果沒有映射關(guān)系的話返回null))
下面這兩行代碼的作用解釋如下:
String[] s=efoodname.split(" "); String[] s01=efoodinfo.split(" ");
可以用它們將一個(gè)字符串中用空格符分隔開的內(nèi)容分離成一個(gè)新的數(shù)組。下面舉一個(gè)例子來說明
public class Test01 { public static void main(String args[]) { String s="My name is Ada"; String[] s01=s.split(" "); for(int i=0;i<s01.length;i++){ System.out.println(s01[i]); } } }
運(yùn)行上面的那個(gè)程序會(huì)出現(xiàn)這樣的結(jié)果:
run: My name is Ada 成功生成(總時(shí)間:0 秒)
說明String[] s01=s.split(" ");這句話的作用是把字符串s中用空格符來分隔開的內(nèi)容分離成一個(gè)一個(gè)的元素并組成一個(gè)新的字符類型的數(shù)組s01,即s01={"My","name","is","Ada"}.
|