创建ListView的基本步骤
参考《疯狂android讲义》第2.5节P94
1、创建一个或者多个ListView
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context=".MainActivity" > <ListView
android:id="@+id/list1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:divider="#f00"
android:dividerHeight="2dp"
android:headerDividersEnabled="false" /> <ListView
android:id="@+id/list2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:divider="#0f0"
android:dividerHeight="2dp"
android:headerDividersEnabled="true" />
</LinearLayout>
2、创建TextViewResource,为每个元素定义其显示属性
array_item1.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tv_item1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="20sp"
android:padding="10dp"
android:shadowColor="#0f0"
android:shadowDx="4"
android:shadowDy="4"
android:shadowRadius="2">
</TextView>
array_item2.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tv_item2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="20sp"
android:padding="10dp"
android:shadowColor="#ff0"
android:shadowDx="4"
android:shadowDy="4"
android:shadowRadius="2">
</TextView>
3、创建Activity,并完成以下三个步骤
package com.ljh.listviewdemo; import android.os.Bundle;
import android.app.Activity;
import android.widget.ArrayAdapter;
import android.widget.ListView; public class MainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); //3、定义每个元素的内容
String[] arr1 = new String[]{"孙悟空","猪八戒","沙僧","唐僧"}; //4、将元素属性及元素内容包装为ArrayAdapter
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(this, R.layout.array_item1, arr1); //5、为ListView设置Adapter
ListView list1 = (ListView) findViewById(R.id.list1);
list1.setAdapter(adapter1); //3、定义每个元素的内容
String[] arr2 = new String[]{"Java","C++","Python","PHP"}; //4、将元素属性及元素内容包装为ArrayAdapter
ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(this, R.layout.array_item2, arr2); //5、为ListView设置Adapter
ListView list2= (ListView) findViewById(R.id.list2);
list2.setAdapter(adapter2);
} }
创建ListView的基本步骤的更多相关文章
- 创建ListView的基本步骤 分类: H1_ANDROID 2013-10-31 23:25 1276人阅读 评论(0) 收藏
参考<疯狂android讲义>第2.5节P94 1.创建一个或者多个ListView <LinearLayout xmlns:android="http://schemas ...
- Android开发10.1:UI组件适配器AdapterView(创建ListView,Adapter接口)
@version:Android4.3 API18 @author:liuxinming 概述 AdapterView继承了ViewGroup,它的本质是容器 ...
- 别以为真懂Openstack: 虚拟机创建的50个步骤和100个知识点(5)
八.KVM 这一步,像virsh start命令一样,将虚拟机启动起来了.虚拟机启动之后,还有很多的步骤需要完成. 步骤38:从DHCP Server获取IP 有时候往往数据库里面,VM已经有了IP, ...
- 别以为真懂Openstack: 虚拟机创建的50个步骤和100个知识点(3)
四.Nova-compute 步骤17:nova-compute接收到请求后,通过Resource Tracker将创建虚拟机所需要的资源声明占用 步骤18:调用Neutron API配置Networ ...
- 创建CrawlSpider爬虫简要步骤
创建CrawlSpider爬虫简要步骤: 1. 创建项目文件: e.g: scrapy startproject douyu (douyu为项目名自定义) 2. 进入项目文件: e.g: cd dou ...
- 【HANA系列】SAP ECLIPSE中创建ABAP项目的步骤
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HANA系列]SAP ECLIPSE中创建AB ...
- Linux下Weblogic创建域方法和步骤
Weblogic 创建域 以weblogic帐号登录(与创建域目录相对应账户) cd /home/weblogic/bea/weblogic92/common/bin 执行./config.sh进入配 ...
- 创建ListView控件
// 创建List控件 HWND hListView = CreateWindow(WC_LISTVIEW ,/*listview 宏的名字*/ L"" ,/*窗口标题*/ WS_ ...
- 使用SimpleAdapter创建ListView
通过ArrayAdapter实现Adapter虽然简单.易用,但ArrayAdapter的功能比较有限.它的每个列表只能是TextView.如果开发者需呀实现更复杂的列表项,则可以考虑使用Simple ...
随机推荐
- 如何在hadoop中控制map的个数
hadooop提供了一个设置map个数的参数mapred.map.tasks,我们可以通过这个参数来控制map的个数.但是通过这种方式设置map的个数,并不是每次都有效的.原因是mapred.map. ...
- requirejs的配置
baseUrl : 所有模块的查找根路径. 当加载纯.js文件(依赖字串以/开头,或者以.js结尾,或者含有协议),不会使用baseUrl. 如未显式设置baseUrl,则默认值是加载require. ...
- 记录android开发博客
1.一国外android开发博客,值得关注 https://blog.stylingandroid.com/page/2/ 2.一个app设计博客,很赞 http://androidniceties. ...
- 愉快的开始 - Windows程序设计(SDK)000
愉快的开始 让编程改变世界 Change the world by program 参考教材 购买链接:Windows程序设计(第5版)(珍藏版)(附CD-ROM光盘1张) 学习环境 视频演示:W ...
- UIAppearance使用详解-备
iOS5及其以后提供了一个比较强大的工具UIAppearance,我们通过UIAppearance设置一些UI的全局效果,这样就可以很方便的实现UI的自定义效果又能最简单的实现统一界面风格,它提供如下 ...
- js判断输入的是单字节还是双字节
计算机上每一个字符.数字.汉字.字母等,都对应着unicode编码,unicode编码小于255的为单字节,大于255.小于65535的为双子节或三字节 查看一个字符对应的unicode编码 var ...
- 实例解析shell子进程(subshell )
http://blog.csdn.net/sosodream/article/details/5683515 http://blog.csdn.net/firefoxbug/article/detai ...
- CDT+Eclipse代码自动提示
1.查看GCC的版本:$gcc -v————————————————————————gcc version 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC)———————— ...
- NSSCanner 提取 指定 字符串
/** * 从msg中提取指定的内容 * * @param msg 字符串集合 * * @return 从msg中提取指定的内容 */ -(NSString*)extractBodyFromMe ...
- Go语言程序的状态监控
Go是很实在的编程语言,从一开始就提供了很详细的运行状态信息.产品上线后的调优和排查疑难杂症都得靠这些状态信息.这边总结一些我们项目里用到的状态监控手段. pprof Go自带了一个pprof工具,这 ...