API Demos 2.3 学习笔记 (20)-- Views-Lists-Array

2024-01-01 20:10

本文主要是介绍API Demos 2.3 学习笔记 (20)-- Views-Lists-Array,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

更多精彩内容,请点击阅读:《API Demos 2.3 学习笔记》


从本节开始,我们开始接触List方面的内容。List部分的内容主要用到控件ListView。根据我的了解,我喜欢把ListView的应用框架分成三层来理解:数据,适配器,UI。其中,数据主要是一系列特定数据的集合,例如,一个字符串数组等;UI主要是ListView,或者包含ListView控件的ListActivity;适配器则有很多,例如:ArrayAdapter<T>, BaseAdapter, CursorAdapter, HeaderViewListAdapter, ListAdapter, ResourceCursorAdapter, SimpleAdapter, SimpleCursorAdapter, SpinnerAdapter, WrapperListAdapter。
这里做一个不太恰当的比喻,来帮助大家理解一下。
我们可以把各种数据理解为,SD卡,mini SD卡,TF卡等上面的数据,而适配器则可以理解为读卡器,UI则可以理解为电脑。不管是什么卡,只要通过读卡器连接电脑,都可以在电脑上浏览并且操作卡上的数据。
ListActivity可以理解为封装了一个ListView对象以及相关操作的Activity。
下面简单介绍怎样使用ArrayAdapter和字符串数组填充ListActivity。
1、首先,创建一个继承自ListActivity的Activity。
public class List1 extends ListActivity {


2、定义或者设置数据源。本实例中使用了一个字符串数组。
//数据源,字符串数组
private String[] mStrings = {
"Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi",
"Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "Airedale",
"Aisy Cendre", "Allgauer Emmentaler", "Alverca", "Ambert", "American Cheese",...}


3、新建一个适配器,将数据源和ListActivity绑定起来。
//设置适配器
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, mStrings));

注:
1、this,代表当前Activity的上下文Context
2、android.R.layout.simple_list_item_1为android系统内置的样式。查看源代码可知,这个样式其实就是一个TextView;
3、数据源,一个字符串数组。


具体效果如下:

注:根据适配器的定义,可以理解如下:
ListView中的每一行都采用 android.R.layout.simple_list_item_1(一个TextView)作为布局,然后将 mStrings中的字符串每行一个,显示在根据上面布局创建的对象上。




下面我们进行实例代码解析:

src-com.example.android.apis.view-List1.java

package com.example.android.apis.view;import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;/*** 一个使用字符串数组作为数据源的listview示例*/
public class List1 extends ListActivity {@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);//设置适配器setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, mStrings));//设置是否启用文本过滤功能getListView().setTextFilterEnabled(true);}//数据源,字符串数组private String[] mStrings = {"Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi","Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "Airedale","Aisy Cendre", "Allgauer Emmentaler", "Alverca", "Ambert", "American Cheese","Ami du Chambertin", "Anejo Enchilado", "Anneau du Vic-Bilh", "Anthoriro", "Appenzell","Aragon", "Ardi Gasna", "Ardrahan", "Armenian String", "Aromes au Gene de Marc","Asadero", "Asiago", "Aubisque Pyrenees", "Autun", "Avaxtskyr", "Baby Swiss","Babybel", "Baguette Laonnaise", "Bakers", "Baladi", "Balaton", "Bandal", "Banon","Barry's Bay Cheddar", "Basing", "Basket Cheese", "Bath Cheese", "Bavarian Bergkase","Baylough", "Beaufort", "Beauvoorde", "Beenleigh Blue", "Beer Cheese", "Bel Paese","Bergader", "Bergere Bleue", "Berkswell", "Beyaz Peynir", "Bierkase", "Bishop Kennedy","Blarney", "Bleu d'Auvergne", "Bleu de Gex", "Bleu de Laqueuille","Bleu de Septmoncel", "Bleu Des Causses", "Blue", "Blue Castello", "Blue Rathgore","Blue Vein (Australian)", "Blue Vein Cheeses", "Bocconcini", "Bocconcini (Australian)","Boeren Leidenkaas", "Bonchester", "Bosworth", "Bougon", "Boule Du Roves","Boulette d'Avesnes", "Boursault", "Boursin", "Bouyssou", "Bra", "Braudostur","Breakfast Cheese", "Brebis du Lavort", "Brebis du Lochois", "Brebis du Puyfaucon","Bresse Bleu", "Brick", "Brie", "Brie de Meaux", "Brie de Melun", "Brillat-Savarin","Brin", "Brin d' Amour", "Brin d'Amour", "Brinza (Burduf Brinza)","Briquette de Brebis", "Briquette du Forez", "Broccio", "Broccio Demi-Affine","Brousse du Rove", "Bruder Basil", "Brusselae Kaas (Fromage de Bruxelles)", "Bryndza","Buchette d'Anjou", "Buffalo", "Burgos", "Butte", "Butterkase", "Button (Innes)","Buxton Blue", "Cabecou", "Caboc", "Cabrales", "Cachaille", "Caciocavallo", "Caciotta","Caerphilly", "Cairnsmore", "Calenzana", "Cambazola", "Camembert de Normandie","Canadian Cheddar", "Canestrato", "Cantal", "Caprice des Dieux", "Capricorn Goat","Capriole Banon", "Carre de l'Est", "Casciotta di Urbino", "Cashel Blue", "Castellano","Castelleno", "Castelmagno", "Castelo Branco", "Castigliano", "Cathelain","Celtic Promise", "Cendre d'Olivet", "Cerney", "Chabichou", "Chabichou du Poitou","Chabis de Gatine", "Chaource", "Charolais", "Chaumes", "Cheddar","Cheddar Clothbound", "Cheshire", "Chevres", "Chevrotin des Aravis", "Chontaleno","Civray", "Coeur de Camembert au Calvados", "Coeur de Chevre", "Colby", "Cold Pack","Comte", "Coolea", "Cooleney", "Coquetdale", "Corleggy", "Cornish Pepper","Cotherstone", "Cotija", "Cottage Cheese", "Cottage Cheese (Australian)","Cougar Gold", "Coulommiers", "Coverdale", "Crayeux de Roncq", "Cream Cheese","Cream Havarti", "Crema Agria", "Crema Mexicana", "Creme Fraiche", "Crescenza","Croghan", "Crottin de Chavignol", "Crottin du Chavignol", "Crowdie", "Crowley","Cuajada", "Curd", "Cure Nantais", "Curworthy", "Cwmtawe Pecorino","Cypress Grove Chevre", "Danablu (Danish Blue)", "Danbo", "Danish Fontina","Daralagjazsky", "Dauphin", "Delice des Fiouves", "Denhany Dorset Drum", "Derby","Dessertnyj Belyj", "Devon Blue", "Devon Garland", "Dolcelatte", "Doolin","Doppelrhamstufel", "Dorset Blue Vinney", "Double Gloucester", "Double Worcester","Dreux a la Feuille", "Dry Jack", "Duddleswell", "Dunbarra", "Dunlop", "Dunsyre Blue","Duroblando", "Durrus", "Dutch Mimolette (Commissiekaas)", "Edam", "Edelpilz","Emental Grand Cru", "Emlett", "Emmental", "Epoisses de Bourgogne", "Esbareich","Esrom", "Etorki", "Evansdale Farmhouse Brie", "Evora De L'Alentejo", "Exmoor Blue","Explorateur", "Feta", "Feta (Australian)", "Figue", "Filetta", "Fin-de-Siecle","Finlandia Swiss", "Finn", "Fiore Sardo", "Fleur du Maquis", "Flor de Guia","Flower Marie", "Folded", "Folded cheese with mint", "Fondant de Brebis","Fontainebleau", "Fontal", "Fontina Val d'Aosta", "Formaggio di capra", "Fougerus","Four Herb Gouda", "Fourme d' Ambert", "Fourme de Haute Loire", "Fourme de Montbrison","Fresh Jack", "Fresh Mozzarella", "Fresh Ricotta", "Fresh Truffles", "Fribourgeois","Friesekaas", "Friesian", "Friesla", "Frinault", "Fromage a Raclette", "Fromage Corse","Fromage de Montagne de Savoie", "Fromage Frais", "Fruit Cream Cheese","Frying Cheese", "Fynbo", "Gabriel", "Galette du Paludier", "Galette Lyonnaise","Galloway Goat's Milk Gems", "Gammelost", "Gaperon a l'Ail", "Garrotxa", "Gastanberra","Geitost", "Gippsland Blue", "Gjetost", "Gloucester", "Golden Cross", "Gorgonzola","Gornyaltajski", "Gospel Green", "Gouda", "Goutu", "Gowrie", "Grabetto", "Graddost","Grafton Village Cheddar", "Grana", "Grana Padano", "Grand Vatel","Grataron d' Areches", "Gratte-Paille", "Graviera", "Greuilh", "Greve","Gris de Lille", "Gruyere", "Gubbeen", "Guerbigny", "Halloumi","Halloumy (Australian)", "Haloumi-Style Cheese", "Harbourne Blue", "Havarti","Heidi Gruyere", "Hereford Hop", "Herrgardsost", "Herriot Farmhouse", "Herve","Hipi Iti", "Hubbardston Blue Cow", "Hushallsost", "Iberico", "Idaho Goatster","Idiazabal", "Il Boschetto al Tartufo", "Ile d'Yeu", "Isle of Mull", "Jarlsberg","Jermi Tortes", "Jibneh Arabieh", "Jindi Brie", "Jubilee Blue", "Juustoleipa","Kadchgall", "Kaseri", "Kashta", "Kefalotyri", "Kenafa", "Kernhem", "Kervella Affine","Kikorangi", "King Island Cape Wickham Brie", "King River Gold", "Klosterkaese","Knockalara", "Kugelkase", "L'Aveyronnais", "L'Ecir de l'Aubrac", "La Taupiniere","La Vache Qui Rit", "Laguiole", "Lairobell", "Lajta", "Lanark Blue", "Lancashire","Langres", "Lappi", "Laruns", "Lavistown", "Le Brin", "Le Fium Orbo", "Le Lacandou","Le Roule", "Leafield", "Lebbene", "Leerdammer", "Leicester", "Leyden", "Limburger","Lincolnshire Poacher", "Lingot Saint Bousquet d'Orb", "Liptauer", "Little Rydings","Livarot", "Llanboidy", "Llanglofan Farmhouse", "Loch Arthur Farmhouse","Loddiswell Avondale", "Longhorn", "Lou Palou", "Lou Pevre", "Lyonnais", "Maasdam","Macconais", "Mahoe Aged Gouda", "Mahon", "Malvern", "Mamirolle", "Manchego","Manouri", "Manur", "Marble Cheddar", "Marbled Cheeses", "Maredsous", "Margotin","Maribo", "Maroilles", "Mascares", "Mascarpone", "Mascarpone (Australian)","Mascarpone Torta", "Matocq", "Maytag Blue", "Meira", "Menallack Farmhouse","Menonita", "Meredith Blue", "Mesost", "Metton (Cancoillotte)", "Meyer Vintage Gouda","Mihalic Peynir", "Milleens", "Mimolette", "Mine-Gabhar", "Mini Baby Bells", "Mixte","Molbo", "Monastery Cheeses", "Mondseer", "Mont D'or Lyonnais", "Montasio","Monterey Jack", "Monterey Jack Dry", "Morbier", "Morbier Cru de Montagne","Mothais a la Feuille", "Mozzarella", "Mozzarella (Australian)","Mozzarella di Bufala", "Mozzarella Fresh, in water", "Mozzarella Rolls", "Munster","Murol", "Mycella", "Myzithra", "Naboulsi", "Nantais", "Neufchatel","Neufchatel (Australian)", "Niolo", "Nokkelost", "Northumberland", "Oaxaca","Olde York", "Olivet au Foin", "Olivet Bleu", "Olivet Cendre","Orkney Extra Mature Cheddar", "Orla", "Oschtjepka", "Ossau Fermier", "Ossau-Iraty","Oszczypek", "Oxford Blue", "P'tit Berrichon", "Palet de Babligny", "Paneer", "Panela","Pannerone", "Pant ys Gawn", "Parmesan (Parmigiano)", "Parmigiano Reggiano","Pas de l'Escalette", "Passendale", "Pasteurized Processed", "Pate de Fromage","Patefine Fort", "Pave d'Affinois", "Pave d'Auge", "Pave de Chirac", "Pave du Berry","Pecorino", "Pecorino in Walnut Leaves", "Pecorino Romano", "Peekskill Pyramid","Pelardon des Cevennes", "Pelardon des Corbieres", "Penamellera", "Penbryn","Pencarreg", "Perail de Brebis", "Petit Morin", "Petit Pardou", "Petit-Suisse","Picodon de Chevre", "Picos de Europa", "Piora", "Pithtviers au Foin","Plateau de Herve", "Plymouth Cheese", "Podhalanski", "Poivre d'Ane", "Polkolbin","Pont l'Eveque", "Port Nicholson", "Port-Salut", "Postel", "Pouligny-Saint-Pierre","Pourly", "Prastost", "Pressato", "Prince-Jean", "Processed Cheddar", "Provolone","Provolone (Australian)", "Pyengana Cheddar", "Pyramide", "Quark","Quark (Australian)", "Quartirolo Lombardo", "Quatre-Vents", "Quercy Petit","Queso Blanco", "Queso Blanco con Frutas --Pina y Mango", "Queso de Murcia","Queso del Montsec", "Queso del Tietar", "Queso Fresco", "Queso Fresco (Adobera)","Queso Iberico", "Queso Jalapeno", "Queso Majorero", "Queso Media Luna","Queso Para Frier", "Queso Quesadilla", "Rabacal", "Raclette", "Ragusano", "Raschera","Reblochon", "Red Leicester", "Regal de la Dombes", "Reggianito", "Remedou","Requeson", "Richelieu", "Ricotta", "Ricotta (Australian)", "Ricotta Salata", "Ridder","Rigotte", "Rocamadour", "Rollot", "Romano", "Romans Part Dieu", "Roncal", "Roquefort","Roule", "Rouleau De Beaulieu", "Royalp Tilsit", "Rubens", "Rustinu", "Saaland Pfarr","Saanenkaese", "Saga", "Sage Derby", "Sainte Maure", "Saint-Marcellin","Saint-Nectaire", "Saint-Paulin", "Salers", "Samso", "San Simon", "Sancerre","Sap Sago", "Sardo", "Sardo Egyptian", "Sbrinz", "Scamorza", "Schabzieger", "Schloss","Selles sur Cher", "Selva", "Serat", "Seriously Strong Cheddar", "Serra da Estrela","Sharpam", "Shelburne Cheddar", "Shropshire Blue", "Siraz", "Sirene", "Smoked Gouda","Somerset Brie", "Sonoma Jack", "Sottocenare al Tartufo", "Soumaintrain","Sourire Lozerien", "Spenwood", "Sraffordshire Organic", "St. Agur Blue Cheese","Stilton", "Stinking Bishop", "String", "Sussex Slipcote", "Sveciaost", "Swaledale","Sweet Style Swiss", "Swiss", "Syrian (Armenian String)", "Tala", "Taleggio", "Tamie","Tasmania Highland Chevre Log", "Taupiniere", "Teifi", "Telemea", "Testouri","Tete de Moine", "Tetilla", "Texas Goat Cheese", "Tibet", "Tillamook Cheddar","Tilsit", "Timboon Brie", "Toma", "Tomme Brulee", "Tomme d'Abondance","Tomme de Chevre", "Tomme de Romans", "Tomme de Savoie", "Tomme des Chouans", "Tommes","Torta del Casar", "Toscanello", "Touree de L'Aubier", "Tourmalet","Trappe (Veritable)", "Trois Cornes De Vendee", "Tronchon", "Trou du Cru", "Truffe","Tupi", "Turunmaa", "Tymsboro", "Tyn Grug", "Tyning", "Ubriaco", "Ulloa","Vacherin-Fribourgeois", "Valencay", "Vasterbottenost", "Venaco", "Vendomois","Vieux Corse", "Vignotte", "Vulscombe", "Waimata Farmhouse Blue","Washed Rind Cheese (Australian)", "Waterloo", "Weichkaese", "Wellington","Wensleydale", "White Stilton", "Whitestone Farmhouse", "Wigmore", "Woodside Cabecou","Xanadu", "Xynotyro", "Yarg Cornish", "Yarra Valley Pyramid", "Yorkshire Blue","Zamorano", "Zanetti Grana Padano", "Zanetti Parmigiano Reggiano"};
}

欢迎大家关注我的微信公众号:

微信公众号:sn0wdr1am


这篇关于API Demos 2.3 学习笔记 (20)-- Views-Lists-Array的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/560377

相关文章

HarmonyOS学习(七)——UI(五)常用布局总结

自适应布局 1.1、线性布局(LinearLayout) 通过线性容器Row和Column实现线性布局。Column容器内的子组件按照垂直方向排列,Row组件中的子组件按照水平方向排列。 属性说明space通过space参数设置主轴上子组件的间距,达到各子组件在排列上的等间距效果alignItems设置子组件在交叉轴上的对齐方式,且在各类尺寸屏幕上表现一致,其中交叉轴为垂直时,取值为Vert

Ilya-AI分享的他在OpenAI学习到的15个提示工程技巧

Ilya(不是本人,claude AI)在社交媒体上分享了他在OpenAI学习到的15个Prompt撰写技巧。 以下是详细的内容: 提示精确化:在编写提示时,力求表达清晰准确。清楚地阐述任务需求和概念定义至关重要。例:不用"分析文本",而用"判断这段话的情感倾向:积极、消极还是中性"。 快速迭代:善于快速连续调整提示。熟练的提示工程师能够灵活地进行多轮优化。例:从"总结文章"到"用

【前端学习】AntV G6-08 深入图形与图形分组、自定义节点、节点动画(下)

【课程链接】 AntV G6:深入图形与图形分组、自定义节点、节点动画(下)_哔哩哔哩_bilibili 本章十吾老师讲解了一个复杂的自定义节点中,应该怎样去计算和绘制图形,如何给一个图形制作不间断的动画,以及在鼠标事件之后产生动画。(有点难,需要好好理解) <!DOCTYPE html><html><head><meta charset="UTF-8"><title>06

学习hash总结

2014/1/29/   最近刚开始学hash,名字很陌生,但是hash的思想却很熟悉,以前早就做过此类的题,但是不知道这就是hash思想而已,说白了hash就是一个映射,往往灵活利用数组的下标来实现算法,hash的作用:1、判重;2、统计次数;

零基础学习Redis(10) -- zset类型命令使用

zset是有序集合,内部除了存储元素外,还会存储一个score,存储在zset中的元素会按照score的大小升序排列,不同元素的score可以重复,score相同的元素会按照元素的字典序排列。 1. zset常用命令 1.1 zadd  zadd key [NX | XX] [GT | LT]   [CH] [INCR] score member [score member ...]

【机器学习】高斯过程的基本概念和应用领域以及在python中的实例

引言 高斯过程(Gaussian Process,简称GP)是一种概率模型,用于描述一组随机变量的联合概率分布,其中任何一个有限维度的子集都具有高斯分布 文章目录 引言一、高斯过程1.1 基本定义1.1.1 随机过程1.1.2 高斯分布 1.2 高斯过程的特性1.2.1 联合高斯性1.2.2 均值函数1.2.3 协方差函数(或核函数) 1.3 核函数1.4 高斯过程回归(Gauss

【学习笔记】 陈强-机器学习-Python-Ch15 人工神经网络(1)sklearn

系列文章目录 监督学习:参数方法 【学习笔记】 陈强-机器学习-Python-Ch4 线性回归 【学习笔记】 陈强-机器学习-Python-Ch5 逻辑回归 【课后题练习】 陈强-机器学习-Python-Ch5 逻辑回归(SAheart.csv) 【学习笔记】 陈强-机器学习-Python-Ch6 多项逻辑回归 【学习笔记 及 课后题练习】 陈强-机器学习-Python-Ch7 判别分析 【学

系统架构师考试学习笔记第三篇——架构设计高级知识(20)通信系统架构设计理论与实践

本章知识考点:         第20课时主要学习通信系统架构设计的理论和工作中的实践。根据新版考试大纲,本课时知识点会涉及案例分析题(25分),而在历年考试中,案例题对该部分内容的考查并不多,虽在综合知识选择题目中经常考查,但分值也不高。本课时内容侧重于对知识点的记忆和理解,按照以往的出题规律,通信系统架构设计基础知识点多来源于教材内的基础网络设备、网络架构和教材外最新时事热点技术。本课时知识

线性代数|机器学习-P36在图中找聚类

文章目录 1. 常见图结构2. 谱聚类 感觉后面几节课的内容跨越太大,需要补充太多的知识点,教授讲得内容跨越较大,一般一节课的内容是书本上的一章节内容,所以看视频比较吃力,需要先预习课本内容后才能够很好的理解教授讲解的知识点。 1. 常见图结构 假设我们有如下图结构: Adjacency Matrix:行和列表示的是节点的位置,A[i,j]表示的第 i 个节点和第 j 个

Node.js学习记录(二)

目录 一、express 1、初识express 2、安装express 3、创建并启动web服务器 4、监听 GET&POST 请求、响应内容给客户端 5、获取URL中携带的查询参数 6、获取URL中动态参数 7、静态资源托管 二、工具nodemon 三、express路由 1、express中路由 2、路由的匹配 3、路由模块化 4、路由模块添加前缀 四、中间件