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

本文介绍如何将Forecast_conditions实体类的数据通过SimpleAdapter适配器整合到ListView中展示,包括实体类设计与适配器实现的详细步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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控件

转载于:https://www.cnblogs.com/qingci/archive/2011/10/20/2219597.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值