List> data=new ArrayList>();
String[] s=efoodname.split(" ");
String[] s01=efoodinfo.split(" ");
for(int i=0;i
Map map=new HashMap();
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);
关于Map的用法与作用:
Objectjava.util.Map.put(Stringkey,Objectvalue)
public abstract Vput (K key, V value)
Maps the specified key to the specified value.(为被指定的键映射被指定的值,也就是说创建一个映射,即让一个指定的键代表一个指定的值)
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.(任何一个值映射到一个指定的键或者NULL(如果没有映射关系的话返回null))
下面这两行代码的作用解释如下:
String[] s=efoodname.split(" ");
String[] s01=efoodinfo.split(" ");
可以用它们将一个字符串中用空格符分隔开的内容分离成一个新的数组。下面举一个例子来说明
public class Test01 {
public static void main(String args[]) {
String s="My name is Ada";
String[] s01=s.split(" ");
for(int i=0;i
System.out.println(s01[i]);
}
}
}
运行上面的那个程序会出现这样的结果:
run:
My
name
is
Ada
成功生成(总时间:0 秒)
说明String[] s01=s.split(" ");这句话的作用是把字符串s中用空格符来分隔开的内容分离成一个一个的元素并组成一个新的字符类型的数组s01,即s01={"My","name","is","Ada"}.