当前位置: 首页 > 编程日记 > 正文

安卓学习-界面-ui-ListView

ListView继承自AbsListView

AbsListView属性

XML属性代码说明
android:choiceMode

setChoiceMode(int choiceMode)

AbsListView.CHOICE_MODE_SINGLE
AbsListView.CHOICE_MODE_MULTIPLE
AbsListView.CHOICE_MODE_MULTIPLE_MODAL

none :无选择模式

singleChoice:允许单选

multipleChoice:允许多选

multipleChoiceModal:允许多选

好像要用android.R.layout.simple_list_item_checked才有效果

ArrayAdapter<String> items=
new ArrayAdapter<String>(getApplicationContext(), 
android.R.layout.simple_list_item_checked, new String[]{"浙江","上海","北京"});
lv.setAdapter(items);

android:drawSelectorOnTopsetDrawSelectorOnTop(boolean onTop)

设置为true, 按住记录不放,颜色会覆盖文字,文字就不是很清楚了

true效果

false效果

不知道这样做的用意是什么?

android:fastScrollEnabled

是否显示快速滚动的按钮,右边那个蓝色的就是,手指快速滚动的会后会显示出来

android:listSelectorsetSelector(Drawable sel)

在选中的记录上绘制drawable,如果设置android:drawSelectorOnTop为true,

则该条记录会被完全覆盖,包括后面的√

android:scrollingCache

当为真时,列表滚动使用绘图缓存。该选项使渲染更快,但占用更多的内存。 默认值为真

不知道有什么用

android:smoothScrollbarsetSmoothScrollbarEnabled(boolean enabled)

完全看不懂

为真时,列表会使用更精确的基于条目在屏幕上的可见像素高度的计算方法。 默认该属性为真,如果你的适配器需要绘制可变高的条目,他应该设为假。 当该属性为真时,你在适配器在显示变高条目时,滚动条的把手会在滚动的 过程中改变大小。当设为假时,列表只使用适配器中的条目数和屏幕上的 可见条目来决定滚动条的属性

android:stackFromBottomsetStackFromBottom(boolean stackFromBottom)

从底部开始显示

android:textFilterEnabledsetTextFilterEnabled(boolean textFilterEnabled)

是否启用过滤,只有adapter设置了filter时才有效果

这样设置

        ArrayAdapter<String> items=new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_checked,list);items.getFilter().filter("测试9");

效果,只显示带 测试9的条目了

android:transcriptMode

setTranscriptMode(int mode)

AbsListView.TRANSCRIPT_MODE_DISABLED
AbsListView.TRANSCRIPT_MODE_NORMAL
AbsListView.TRANSCRIPT_MODE_ALWAYS_SCROLL

属性

disabled:

normal:添加记录时当最后一列可见时会自动往下滚动

alwaysScroll:添加记录时,直接滚动到最后一条新增加的记录

如何增加记录呢

如下:

        btn=(Button)findViewById(R.id.button1);btn.setOnClickListener(new OnClickListener() {public void onClick(View v) {//list里增加记录list.add("新增加的");//刷新记录
                items.notifyDataSetChanged();}});

效果:添加后直接滚动到最后了,这个效果还不错

ListView属性

XML属性代码说明
android:dividersetDivider(Drawable divider)分隔条
android:dividerHeightsetDividerHeight(int height)

分隔条高度

android:entries

直接指定资源文件,代码都不用写了

array1.xml

<?xml version="1.0" encoding="utf-8"?>
<resources><string-array name="items"><item >测试1</item><item >测试2</item><item >测试3</item><item >测试4</item></string-array>
</resources>
    <ListViewandroid:id="@+id/listView1"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="@color/color1"android:entries="@array/items"/>

android:footerDividersEnabledsetFooterDividersEnabled(boolean footerDividersEnabled)

设置为false,则不再footer和view之间绘制分隔线

1.添加footer按钮

        View view=LayoutInflater.from(MainActivity.this).inflate(R.layout.footer, null);//必须在setAdapter前设置,否则没效果lv.addFooterView(view);    

2.设置为true时

3.设置为false时,footer前少了根线

android:headerDividersEnabled

setHeaderDividersEnabled(boolean headerDividersEnabled)

设置为false,则不在header和view之间绘制分隔先

例子1

listview最后增加一个加载更多的按钮

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical" ><!-- android:transcriptMode 设置成alwaysScroll,这样点击添加按钮后会自动滚动到最后 --><ListViewandroid:id="@+id/listView1"android:layout_width="match_parent"android:layout_height="wrap_content"android:choiceMode="singleChoice"android:background="@color/color1"android:divider="#000"android:dividerHeight="1dp"android:transcriptMode="alwaysScroll"></ListView>
</LinearLayout>
View Code

footer.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent" ><Buttonandroid:id="@+id/button1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentTop="true"android:layout_centerHorizontal="true"android:text="加载更多" /></RelativeLayout>
View Code

MainActivity.java

public class MainActivity extends Activity {ListView lv;Button btn;ArrayList<String> list;ArrayAdapter<String> items;int index=1;protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);lv=(ListView)findViewById(R.id.listView1);list=new ArrayList<String> ();for(int i=1;i<=10;i++){list.add("测试"+index);index=index+1;}items = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_checked,list);View view=LayoutInflater.from(MainActivity.this).inflate(R.layout.footer, null);btn=(Button)view.findViewById(R.id.button1);btn.setOnClickListener(new OnClickListener() {public void onClick(View v) {for(int i=1;i<=10;i++){list.add("测试"+index);index=index+1;}items.notifyDataSetChanged();}});//必须在setAdapter前设置,否则没效果
        lv.addFooterView(view);        lv.setAdapter(items);}
}
View Code

转载于:https://www.cnblogs.com/weijj/p/3951326.html

相关文章:

swift 浮点型字符串的运算

// 1 两个浮点字符串之间的运算 let str1 "1.3"; let str2 "2.4"; let val1 Double(str1); let val2 Double(str2);let val3 CGFloat(Double(str1)!) * CGFloat(Double(str2)!);print(val3);// 2 string 转 double 不失精度 let formattor NumberFo…

为什么要在JavaScript中使用静态类型? (使用Flow进行静态打字的4部分入门)

by Preethi Kasireddy通过Preethi Kasireddy 为什么要在JavaScript中使用静态类型&#xff1f; (使用Flow进行静态打字的4部分入门) (Why use static types in JavaScript? (A 4-part primer on static typing with Flow)) As a JavaScript developer, you can code all day …

客户端如何连接 DataSnap Server 调用服务的方法

一般http访问的地址是 http://localhost:8099/datasnap/rest/TServerMethods1/EchoString/abc 一、用FDConnection1连接Datasnap服务器 FireDAC 连接Datasnap服务端。这个是tcp协议连接通讯&#xff0c;长连接。服务端不是没个方法都建立实例释放实例&#xff0c;而是连接的时…

Solr_全文检索引擎系统

Solr介绍&#xff1a; Solr 是Apache下的一个顶级开源项目&#xff0c;采用Java开发&#xff0c;它是基于Lucene的全文搜索服务。Solr可以独立运行在Jetty、Tomcat等这些Servlet容器中。 Solr的作用&#xff1a; solr是一个现成的全文检索引擎系统&#xff0c; 放入tomcat下可以…

swift 数组 filter reduce sort 等方法

数组的常用方法 swift 数组有很多的操作方法&#xff0c;但是用的时候用常常想不起来&#xff0c;就列出来看看 map 和 flatMap对数组中的元素进行变形操作filter主要对数组进行过滤reduce主要对数组进行计算sort对数组进行排序forEach循环遍历每一个元素min 和 max找出数组中…

im和音视频开发哪个更好_找时间成为更好的开发人员

im和音视频开发哪个更好There’s no time for anything. At least that’s how it feels doesn’t it? No time to learn all the things you think you need to learn to stay ahead of the curve. No time to go back and refactor that ugly piece of code. It works (sort…

4-8 同义词

雅思阅读&#xff1a;剑4~剑8阅读的所有同义词转换 雅思必考词汇 Cambridge 4 TEST 1 1. ignorepay no attentionnot pay any attentiontake no noticenot take any notice忽略&#xff0c;无视v. 2. encounterfaceconfrontmeet遇见&#xff0c;遭遇v. 3. mistaken viewmisconc…

swift可选类型

import UIKitvar array1 ["1","2","3","4","5"];// 1 if let 是一个组合关键字 来进行可选绑定 // 解决Optional对象解包时产生空对象的处理。 for i in array1 {print(i); }if let idx array1.firstIndex(of: "4&q…

java 配置及Eclipse安装

jdk下载 点我~ Java SE Development Kit 8u20 You must accept the Oracle Binary Code License Agreement for Java SE to download this software. Accept License Agreement Decline License Agreement Thank you for accepting the Oracle Binary Code License Agree…

golang 命令行_如何使用Golang编写快速有趣的命令行应用程序

golang 命令行by Peter Benjamin彼得本杰明(Peter Benjamin) 如何使用Golang编写快速有趣的命令行应用程序 (How to write fast, fun command-line applications with Golang) A while back, I wrote an article about “Writing Command-Line Applications in NodeJS”.不久前…

【Pyhon 3】: 170104:优品课堂: GUI -tkinter

from tkinter import * root Tk() root.title("BMS 图书管理系统") lbl Label(root, text书名:)#(1) lbl.pack() #(2) lbl.place(45.50) #(3) web 早期布局&#xff0c;&#xff0c; 常见。 lbl.grid(row0, column0) # web 早期布局&#xff0c;&#xff0c; 常见…

swift Sequence 和 SubSequence

1 序列 Sequence 序列协议是集合类型结构中的基础。 一个序列是代表有一系列具有相同类型的值&#xff0c;并且对这些值进行迭代。 协议中主要有两个参数&#xff0c;一个是元素Element&#xff0c;一个就是迭代器Iterator /// A type representing the sequences elements.…

PDF数据提取------1.介绍

1.关于PDF文件 PDF&#xff08;Portable Document Format的简称&#xff0c;意为“便携式文件格式”&#xff09;是由Adobe Systems在1993年用于文件交换所发展出的文件格式。它的优点在于跨平台、能保留文件原有格式&#xff08;Layout&#xff09;、开放标准&#xff0c;能自…

javascript_治愈JavaScript疲劳的研究计划

javascriptby Sacha Greif由Sacha Greif 治愈JavaScript疲劳的研究计划 (A Study Plan To Cure JavaScript Fatigue) Like everybody else, I recently came across Jose Aguinaga’s post “How it feels to learn JavaScript in 2016”.像其他所有人一样&#xff0c;我最近遇…

SQL Server中SELECT会真的阻塞SELECT吗?

在SQL Server中&#xff0c;我们知道一个SELECT语句执行过程中只会申请一些意向共享锁(IS) 与共享锁(S), 例如我使用SQL Profile跟踪会话86执行SELECT * FROM dbo.TEST WHERE OBJECT_ID 1 这个查询语句&#xff0c;其申请、释放的锁资源的过程如下所示&#xff1a; 而且从最常见…

appium IOS真机测试

看了 http://blog.csdn.net/today520/article/details/36378805 的文章&#xff0c;终于在真机上面测试成功。 由于没有开发者账号&#xff0c;不能发布应用到机器上面。所以就用了网易新闻的客户端来测试 没有开发者账号&#xff0c;貌似不能真正的开始测试。只能启动一下客户…

siwft 写时复制 Copy-On-Write

写时复制 Copy-On-Write 1 定义 在siwft 标准库中&#xff0c;Array&#xff0c;Dictionary&#xff0c;Set这样的集合类型是通过写时复制来实现的。 import Foundationvar a1 [1,2,3]; var a2 a1;// 将a1 复制给 a2&#xff0c;地址打印结果是相同的// 0x1--0x2--0x3 pri…

超越技术分析_超越技术面试

超越技术分析by Jaime J. Rios由Jaime J. Rios 超越技术面试 (Transcending the Technical Interview) “Wow. What a chastening and shameful experience that was.”“哇。 那真是一种令人st目结舌的经历。” This was my immediate mental reaction after I completed my…

轻松获取LAMP,LNMP环境编译参数配置

轻松获取LAMP&#xff0c;LNMP环境编译参数配置 作者:Mr.Xiong /分类:系统管理 字号&#xff1a;L M S大家是否遇到过去了新公司&#xff0c;公司内的LAMP&#xff0c;LNMP等所有的环境都是配置好的&#xff08;已经在提供服务了&#xff09;&#xff0c;公司又没有留下部署文档…

java内存分配--引用

栈内存 对象地址 堆内存 存放属性 public class TestDemo{ public static void main(String args[]){ Person perA new Person(); //出现new百分之百就是要申请堆内存 perA.name"王强"&#xff1b; //perA 地址存放在栈内存中&#xff0c;同一块内存只能存…

iOS NSObject对象内存大小

NSObject内存大小 类的本质是结构体 无须赘述 struct NSObject { Class isa; };一个类对象的实例大小是8个字节 之所以打印出的16个字节&#xff0c;是因为一个NSObject 最小开辟16个字节 NSObject *obj [[NSObject alloc]init];// class_getInstanceSize 这是runtime 获…

客户端渲染 服务端渲染_这就是赢得客户端渲染的原因

客户端渲染 服务端渲染A decade ago, nearly everyone was rendering their web applications on the server using technologies like ASP.NET, Ruby on Rails, Java, and PHP.十年前&#xff0c;几乎每个人都使用ASP.NET&#xff0c;Ruby on Rails&#xff0c;Java和PHP等技术…

java多线程三之线程协作与通信实例

多线程的难点主要就是多线程通信协作这一块了&#xff0c;前面笔记二中提到了常见的同步方法&#xff0c;这里主要是进行实例学习了&#xff0c;今天总结了一下3个实例&#xff1a; 1、银行存款与提款多线程实现&#xff0c;使用Lock锁和条件Condition。 附加 &#xff1a;…

Java8中Lambda表达式的10个例子

Java8中Lambda表达式的10个例子 例1 用Lambda表达式实现Runnable接口 Java代码 //Before Java 8: new Thread(new Runnable() { Override public void run() { System.out.println("Before Java8, too much code for too little to do"); } }).start(); …

OC的对象的分类

OC的对象分类 一 oc的对象分类主要分为3种 1 instance 对象&#xff1a; 实例对象就是通过alloc 出来的对象&#xff0c;一个类每一次的alloc都会产生一个新的实例对象 StudentA *a [[StudentA alloc]init];StudentA *b [[StudentA alloc]init];// 打印结果如下 地址是明显…

如何在国内上medium_在Medium上写作的风格指南

如何在国内上mediumAfter spending more than 1,000 hours writing and editing stories for our Medium publication, I’ve decided to create this living style guide for contributors. Feel free to use it for your publication as well.在花了1000多个小时为我们的《中…

C# webform上传图片并生成缩略图

其实里面写的很乱&#xff0c;包括修改文件名什么的都没有仔细去写&#xff0c;主要是想记录下缩略图生成的几种方式 &#xff0c;大家明白就好! 1 void UpImgs()2 {3 if (FileUpload1.HasFile)4 {5 string fileContentType FileUpload1.Pos…

ios中的自动释放池

自动释放池中是否有虑重功能 1 autoreleasepool { 2 UIView *view [UIView alloc] init] autorelease]; 3 [view autorelease]; 4 } 这样写在自动释放池的队列中是两个对象还是一个对象&#xff0c;就是说把view加到自动释放池的队列时&#xff0c;队列本身是…

arch linux安装_如何从头开始安装Arch Linux

arch linux安装by Andrea Giammarchi由Andrea Giammarchi In this article, youll learn how to install Arch Linux from scratch… and in about 5 minutes. So lets get to it.在本文中&#xff0c;您将学习如何从头开始安装Arch Linux&#xff0c;大约需要5分钟。 因此&am…

CoreCRM 开发实录 —— Profile

再简单的功能&#xff0c;也需要一坨代码的支持。Profile 的编辑功能主要就是修改个人的信息。比如用户名、头像、性别、电话……虽然只是一个编辑界面&#xff0c;但添加下来&#xff0c;涉及了6个文件的修改和7个新创建的文件。各种生成的和手写的代码&#xff0c;共有934行之…