Android入门第六篇之ListView (一)

本文介绍如何在Android应用中实现ListView,包括准备数据、构建适配器及显示ListView等步骤。通过示例代码详细展示了ListView的基本用法。

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

ListView是一个经常用到的控件,ListView里面的每个子项Item可以使一个字符串,也可以是一个组合控件。先说说ListView的实现:

1.准备ListView要显示的数据

2.使用 一维或多维 动态数组 保存数据;

2.构建适配器 简单地来说, 适配器就是 Item数组 动态数组 有多少元素就生成多少个Item;

3.把 适配器 添加到ListView,并显示出来。


main.xml代码如下,很简单,也不需要多做解释了:

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout   
  3.         android:id="@+id/LinearLayout01"   
  4.         android:layout_width="fill_parent"   
  5.         android:layout_height="fill_parent"   
  6.         xmlns:android="http://schemas.android.com/apk/res/android">  
  7.           
  8.         <ListView android:layout_width="wrap_content"   
  9.                   android:layout_height="wrap_content"   
  10.                   android:id="@+id/MyListView">  
  11.         </ListView>  
  12. </LinearLayout>  

 

my_listitem.xml的代码如下,my_listitem.xml用于设计ListView的Item:

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout   
  3.         android:layout_width="fill_parent"   
  4.         xmlns:android="http://schemas.android.com/apk/res/android"   
  5.         android:orientation="vertical"  
  6.         android:layout_height="wrap_content"   
  7.         android:id="@+id/MyListItem"   
  8.         android:paddingBottom="3dip"   
  9.         android:paddingLeft="10dip">  
  10.         <TextView   
  11.                 android:layout_height="wrap_content"   
  12.                 android:layout_width="fill_parent"   
  13.                 android:id="@+id/ItemTitle"   
  14.                 android:textSize="30dip">  
  15.         </TextView>  
  16.         <TextView   
  17.                 android:layout_height="wrap_content"   
  18.                 android:layout_width="fill_parent"   
  19.                 android:id="@+id/ItemText">  
  20.         </TextView>  
  21. </LinearLayout>  

 

解释一下,里面用到的一些属性:

1.paddingBottom="3dip",Layout往底部留出3个像素的空白区域

2.paddingLeft="10dip",Layout往左边留出10个像素的空白区域

3.textSize="30dip",TextView的字体为30个像素那么大。

 

最后就是JAVA的源代码:

  1. public void onCreate(Bundle savedInstanceState) {  
  2.     super.onCreate(savedInstanceState);  
  3.     setContentView(R.layout.main);  
  4.     //绑定XML中的ListView,作为Item的容器   
  5.     ListView list = (ListView) findViewById(R.id.MyListView);  
  6.       
  7.     //生成动态数组,并且转载数据   
  8.     ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();  
  9.     for(int i=0;i<30;i++)  
  10.     {  
  11.         HashMap<String, String> map = new HashMap<String, String>();  
  12.         map.put("ItemTitle""This is Title.....");  
  13.         map.put("ItemText""This is text.....");  
  14.         mylist.add(map);  
  15.     }  
  16.     //生成适配器,数组===》ListItem   
  17.     SimpleAdapter mSchedule = new SimpleAdapter(this//没什么解释   
  18.                                                 mylist,//数据来源    
  19.                                                 R.layout.my_listitem,//ListItem的XML实现   
  20.                                                   
  21.                                                 //动态数组与ListItem对应的子项           
  22.                                                 new String[] {"ItemTitle""ItemText"},   
  23.                                                   
  24.                                                 //ListItem的XML文件里面的两个TextView ID   
  25.                                                 new int[] {R.id.ItemTitle,R.id.ItemText});  
  26.     //添加并且显示   
  27.     list.setAdapter(mSchedule);  

}

基于C2000 DSP的电力电子、电机驱动和数字滤波器的仿真模型构建及其C代码实现方法。首先,在MATLAB/Simulink环境中创建电力电子系统的仿真模型,如三相逆变器,重点讨论了PWM生成模块中死区时间的设置及其对输出波形的影响。接着,深入探讨了C2000 DSP内部各关键模块(如ADC、DAC、PWM定时器)的具体配置步骤,特别是EPWM模块采用上下计数模式以确保对称波形的生成。此外,还讲解了数字滤波器的设计流程,从MATLAB中的参数设定到最终转换为适用于嵌入式系统的高效C代码。文中强调了硬件在环(HIL)和支持快速原型设计(RCP)的重要性,并分享了些实际项目中常见的陷阱及解决方案,如PCB布局不当导致的ADC采样异常等问题。最后,针对中断服务程序(ISR)提出了优化建议,避免因ISR执行时间过长而引起的系统不稳定现象。 适合人群:从事电力电子、电机控制系统开发的技术人员,尤其是那些希望深入了解C2000 DSP应用细节的研发工程师。 使用场景及目标:①掌握利用MATLAB/Simulink进行电力电子设备仿真的技巧;②学会正确配置C2000 DSP的各项外设资源;③能够独立完成从理论设计到实际产品落地全过程中的各个环节,包括但不限于数字滤波器设计、PWM信号生成、ADC采样同步等。 其他说明:文中提供了大量实用的代码片段和技术提示,帮助读者更好地理解和实践相关知识点。同时,也提到了些常见错误案例,有助于开发者规避潜在风险。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值