1. 通过继承Activity实现ListView

1.1 在XML布局文件中实现一个ListView

  <ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/listView"
android:layout_below="@+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="42dp" />

1.2 在MainActivity中实现代码

  ListView listView = (ListView) findViewById(R.id.listView);
String [] name = new String[]{"A","B","C","D","E","F","Aa","Ba","Ca","Da","Ea","Fa"};
ArrayAdapter<String> arrayAdapter= new ArrayAdapter<String>(this,android.R.layout.simple_expandable_list_item_1,name);
listView.setAdapter(arrayAdapter);

第一步:建立数据源

  String [] name = new String[]{"A","B","C","D","E","F","Aa","Ba","Ca","Da","Ea","Fa"};

第二步:建立Adapter并且绑定数据源

  ArrayAdapter<String> arrayAdapter= new ArrayAdapter<String>(this,android.R.layout.simple_expandable_list_item_1,name);

第三步:将Adapter绑定UI

   listView.setAdapter(arrayAdapter);

      

2. 通过继承ListViewActivity实现ListView

2.1 XML文件

不用指定Layout,如果一定要指定话,要将id设为android:id="@android:id/list"

 <ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@android:id/list"
android:layout_below="@+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="42dp" />

2.2 继承ListActivity

 public class MainActivity extends ListActivity {

     @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String [] name = new String[]{"A","B","C","D","E","F","Aa","Ba","Ca","Da","Ea","Fa"};
ArrayAdapter<String> arrayAdapter= new ArrayAdapter<String>(this,android.R.layout.simple_expandable_list_item_1,name);
setListAdapter(arrayAdapter);
}

如果设定XML文件,且指定id为android:id="@android:id/list"

可以用 ListView listView = getListView();来得到这个id为list的listView,然后就可以对这个listView进行操作了。

 

ListView 介绍的更多相关文章

  1. ListView介绍

    原文:http://blog.csdn.net/qingye_love/article/details/13772391?utm_source=tuicool&utm_medium=refer ...

  2. ListView初探

    一.ListView介绍 在Android开发中ListView是比较常用的控件,常用于以列表的形式显示数据集及根据数据的长度自适应显示. ListView通常有两个主要功能点: (1)将数据集填充到 ...

  3. ListView用法及加载数据时的闪烁问题和加载数据过慢问题

    ListView介绍及添加数据时的闪烁问题 1.     ListView类 1.1 ListView常用的基本属性: (1)FullRowSelect:设置是否行选择模式.(默认为false) 提示 ...

  4. Android开发具体解释之ListView具体解释一

    列表ListView介绍和实例  1.ListView  -- ListActivity -- ListAdapter  2.ArrayAdapter结合ListView进行显示  3.SimpleA ...

  5. Android(java)学习笔记186:对ListView等列表组件中数据进行增、删、改操作

    1.ListView介绍 解决大量的相似的数据显示问题 采用了MVC模式: M: model (数据模型) V:  view  (显示的视图) C: controller 控制器 入门案例: acit ...

  6. Android(java)学习笔记129:对ListView等列表组件中数据进行增、删、改操作

    1. ListView介绍 解决大量的相似的数据显示问题 采用了MVC模式: M: model (数据模型) V:  view  (显示的视图) C: controller 控制器 入门案例: aci ...

  7. RecyclerView使用介绍

    来源 http://jinyudong.com/2014/11/13/Introduce-RecyclerView-%E4%B8%80/ 编辑推荐:稀土掘金,这是一个针对技术开发者的一个应用,你可以在 ...

  8. 重新想象 Windows 8.1 Store Apps 系列文章索引

    [源码下载] [重新想象 Windows 8 Store Apps 系列文章] 重新想象 Windows 8.1 Store Apps 系列文章索引 作者:webabcd 1.重新想象 Windows ...

  9. Android利用数据库传送数据

    ---恢复内容开始--- 一.建表 //通过SQLiteDatabase 创建数据库stu.db3 final SQLiteDatabase db = SQLiteDatabase.openOrCre ...

随机推荐

  1. 为Play初学者准备的Scala基础知识

    1 前言 本文的主要目的是为了让Play Framework的初学者快速了解Scala语言,算是一篇Play Framework的入门前传吧.使用PlayFramework可以极大的提高开发效率,但是 ...

  2. 仿中关村win8频道(win8.zol.com.cn)下的tab效果

    最近觉得中关村win8频道下的那个Tab效果很好看. 一时兴起就自己做了一个.觉得还蛮不错的,特地来给大家分享一下.以下是相关的HTML页面写法: <div class="popula ...

  3. Sql Server + ADO.NET

    MsSql-http://www.cnblogs.com/zhangwei595806165/archive/2012/02/23/2364746.html 协议:Shared Memory :效率最 ...

  4. OpenCV探索之路(三):滤波操作

    滤波处理分为两大类:线性滤波和非线性滤波.OpenCV里有这些滤波的函数,使用起来非常方便,现在简单介绍其使用方法. 线性滤波:方框滤波.均值滤波.高斯滤波 方框滤波 #include<open ...

  5. Day1-模块初识

    模块,也叫库,分为标准库和第三方库.标准库,直接导入使用,比如import getpass:第三方库,需下载安装才能使用,比如paramiko: 一.sys模块 import sys print(sy ...

  6. js 高级算法 - 动态规划

    主要是看了<数据结构与算法>有所感悟,虽然这本书被挺多人诟病的,说这有漏洞那有漏洞,但并不妨碍我们从中学习知识. 其实像在我们前端的开发中,用到的高级算法并不多,大部分情况if语句,for ...

  7. 关于Cookie的知识的总结

    Cookie的类型 会话cookie和持久cookie 会话cookie是一种临时cookie,它记录了用户访问站点时的设置和偏好,当用户退出浏览器时,会话cookie就会被删除. 持久cookie的 ...

  8. Eclipse之JSON导包

    1.选中要导包的工程-–>2.右击选择创建文件夹--->3.将要导的包复制到该文件夹下--–>4.右击要导入的包-->5.选择Build path->Add to Bui ...

  9. NLTK学习笔记(一):语言处理和Python

    目录 [TOC] nltk资料下载 import nltk nltk.download() 其中,download() 参数默认是all,可以在脚本里面加上nltk.download(需要的资料库) ...

  10. nodejs 开发指南 书中小项目 代码

    最近 在学习node.js 先看了下语法 ,然后就看这个开发指南感觉书还是很有用,但是代码太旧了,网上也没有最新的,所以就自己查着前人的痕迹和自己修改,现在可以跑了. https://github.c ...