创建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 ...
随机推荐
- github多人协作
1.字符串处理(编码原理) git clone git@github.com:lookphp/LaravelCms.git git add . git commit -m "修改的内容-需要 ...
- debian系统下安装ssh服务
它是什么?? SSH 为 Secure Shell 的缩写,简单地说,SSH 为建立在应用层基础上的安全协议.SSH 是目前较可靠,专为远程登录会话和其他网络服务提供安全性的协议.利用 SSH 协议可 ...
- Block(一)基础-备
一.概述 Block是C级别的语法和运行时特性.Block比较类似C函数,但是Block比之C函数,其灵活性体现在栈内存.堆内存的引用,我们甚至可以将一个Block作为参数传给其他的函数或者Block ...
- 把C#程序(含多个Dll)合并打包成单一文件
实现的方式有多种. 1 Mono 项目中有一个工具,mono的一个附属工具mkbundle.(在Xamarin未被收购开源前,它是加密的商业软件.http://www.cnblogs.com/bins ...
- 关于在C#中实现AOP 拦截编程模式的新的探索
前面有篇文章,是从其他个人博客中贴过来的.地址:http://www.lanhusoft.com/Article/240.html 作者总结实现的挺好. 但是.不能不考虑性能!!使用 ContextB ...
- 【转】图文并茂 Ubuntu使用Thunderbird方法指南
原文网址:http://os.51cto.com/art/201101/243445.htm Ubuntu 是一个启动速度超快.界面友好.安全性好的操作系统,它适用于桌面电脑.笔记本电脑.服务器以及上 ...
- FlexComboBoxTree
在我的CSDN资源中有项目工程文件.下载导入工程即可看到效果,下面是地址. http://download.csdn.net/detail/cym_lmy/6326053 MyCombBoxTree1 ...
- JAVA获得系统配置文件的System Properties
来个java获得系统配置文件的 public class SystemProperties { public static void main(String[] args) { Properties ...
- MyWidget【简单自制控件】
#coding=gbk from PyQt4 import QtGui,QtCore import random class MyWidget(QtGui.QWidget): def __init__ ...
- (转)Tomcat 7 访问 Manager 和 Host Manager
配置好 Tomcat 7.0 后,在 tomcat-users.xml 中配置用户角色来访问 localhost:8080 的这样三个按钮总出现问题: Server Status Manager Ap ...