创建ListView的基本步骤 分类: H1_ANDROID 2013-10-31 23:25 1276人阅读 评论(0) 收藏
参考《疯狂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的基本步骤 分类: H1_ANDROID 2013-10-31 23:25 1276人阅读 评论(0) 收藏的更多相关文章
- 认识C++中的临时对象temporary object 分类: C/C++ 2015-05-11 23:20 137人阅读 评论(0) 收藏
C++中临时对象又称无名对象.临时对象主要出现在如下场景. 1.建立一个没有命名的非堆(non-heap)对象,也就是无名对象时,会产生临时对象. Integer inte= Integer(5); ...
- 动态链接库(DLL) 分类: c/c++ 2015-01-04 23:30 423人阅读 评论(0) 收藏
动态链接库:我们经常把常用的代码制作成一个可执行模块供其他可执行文件调用,这样的模块称为链接库,分为动态链接库和静态链接库. 对于静态链接库,LIB包含具体实现代码且会被包含进EXE中,导致文件过大, ...
- Dungeon Master 分类: 搜索 POJ 2015-08-09 14:25 4人阅读 评论(0) 收藏
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20995 Accepted: 8150 Descr ...
- 哈夫曼树-Fence Repair 分类: 树 POJ 2015-08-05 21:25 2人阅读 评论(0) 收藏
Fence Repair Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 32424 Accepted: 10417 Descri ...
- Babelfish 分类: 哈希 2015-08-04 09:25 2人阅读 评论(0) 收藏
Babelfish Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 36398 Accepted: 15554 Descripti ...
- Windows7下QT5开发环境搭建 分类: QT开发 2015-03-09 23:44 65人阅读 评论(0) 收藏
Windows7下QT开法环境常见搭配方法有两种. 第一种是:QT Creator+QT SDK: 第二种是:VS+qt-vs-addin+QT SDK: 以上两种均可,所需文件见QT社区,QT下载地 ...
- short-path problem (Floyd) 分类: ACM TYPE 2014-09-01 23:58 100人阅读 评论(0) 收藏
#include <cstdio> #include <iostream> #include <cstring> using namespace std; cons ...
- short-path problem (Dijkstra) 分类: ACM TYPE 2014-09-01 23:51 111人阅读 评论(0) 收藏
#include <cstdio> #include <iostream> #include <cstring> using namespace std; cons ...
- NYOJ-79 拦截导弹 AC 分类: NYOJ 2014-01-01 23:25 167人阅读 评论(0) 收藏
#include<stdio.h> int main(){ int num[1000]={0}; int n,m,x,y; scanf("%d",&n); wh ...
随机推荐
- Linux - 用 Konstruct 安装 KDE 3.x
make-kde3.x Linux - 用 Konstruct 安装 KDE 3.x 找个截图工具 khtml2png (http://khtml2png.sourceforge.net/), 现在都 ...
- thinkphp内置标签简单讲解
thinkphp内置标签简单讲解 1.volist循环 name 需要遍历的数据 id 类似于foreach中 value offset 截取数据起始位置 length 截取数据的个数 mod 奇偶数 ...
- Flume的可管理性
Flume的可管理性 所有agent和Collector由master统一管理,这使得系统便于维护. 多master情况,Flume利用 ZooKeeper和gossip,保证动态配置数据的一致性. ...
- Activity Test1
源代码下载(免积分) :下载 Acitivty測试的API的父类是InstrumentationTestCase.这个类可以获取Instrumentation.来操作Activity. 对于acti ...
- 38.IntelliJ IDEA中创建Web聚合项目(Maven多模块项目)
转自:https://blog.csdn.net/u012702547/article/details/77431765 Eclipse用多了,IntelliJ中创建Maven聚合项目可能有小伙伴还不 ...
- Leetcode-求两数之和
题目: 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标. 你可以假设每种输入只会对应一个答案.但是,你不能重复利用这个数组中 ...
- 【干货】前端开发者最常用的六款IDE
一.Visual Studio Code 下载地址:https://code.visualstudio.com/ 功能介绍: 微软在2015年4月30日Build 开发者大会上正式宣布了 Visual ...
- Android Material风格的应用(二)--RecyclerView
添加RecyclerView Android Material风格的应用(一)--AppBar TabLayoutAndroid Material风格的应用(二)--RecyclerViewAndro ...
- Dcloud开发webApp踩过的坑
Dcloud开发webApp踩过的坑 一.总结 一句话总结:HTML5+扩展了JavaScript对象plus,使得js可以调用各种浏览器无法实现或实现不佳的系统能力,设备能力如摄像头.陀螺仪.文件系 ...
- SpringMVC响应Ajax请求(@Responsebody注解返回页面)
项目需求描述:page1中的ajax请求Controller,Controller负责将service返回的数据填充到page2中,并将page2整个页面返回到page1中ajax的回调函数. 一句话 ...