小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

Android中List與Map<String,Object>及SimpleAdapter用來存儲(chǔ)數(shù)據(jù)并展示出來的聯(lián)合用法

 博雅書屋lhs 2014-04-07

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>的用法與作用:

 

Object java.util.Map.put(String key, Object value)

public abstract V put (K key, V value)

Since: API Level 1

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"}.

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多