Android绑定对象到ListView中(知识积累)

public void bindToListView(List<Forecast_conditions> conditionsList)
    {
    	 //SimpleAdapter simpleAdapter=new SimpleAdapter(this,conditionsList,R.layout.list_item, new String[]{"day_of_week","low","high","icon","condition"},new int[]{R.id.WeekTextView,R.id.lowTextView,R.id.HighTextView,R.id.imageView1,R.id.CondtionTextView});
    	
    //	SimpleAdapter simpleAdapter=new 
    	 
    	// m_weatherListView.setAdapter(simpleAdapter);\
    	
    	List<HashMap<String, Object>> hashMaplst=new ArrayList<HashMap<String,Object>>();
    	
    	for (Forecast_conditions forecast_conditions : conditionsList) {
			HashMap<String, Object> item=new HashMap<String, Object>();
			item.put("day_of_week", forecast_conditions.getDay_of_week());
			item.put("low", forecast_conditions.getLow());
			item.put("high", forecast_conditions.getHigh());
			item.put("icon", forecast_conditions.getHigh());
			item.put("condition", forecast_conditions.getCondition());
			
			hashMaplst.add(item);
		}
    	
    	SimpleAdapter simpleAdapter=new SimpleAdapter(this,hashMaplst,R.layout.list_item, new String[]{"day_of_week","low","high","icon","condition"},new int[]{R.id.WeekTextView,R.id.lowTextView,R.id.HighTextView,R.id.imageView1,R.id.CondtionTextView});
    	m_weatherListView.setAdapter(simpleAdapter);
    	
    	 
    }


//Forecast_conditions 是实体类
//本实例是第一次做Android从各方查来写的代码,很多地方设计不合理。  所以仅供参考  -。-

  m_weatherListView是ListView控件

posted @ 2011-10-20 22:28  Sir。  阅读(2495)  评论(0编辑  收藏  举报