View(视图)——ListView之ArrayAdapter

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     xmlns:tools="http://schemas.android.com/tools"
 4     android:layout_width="match_parent"
 5     android:layout_height="match_parent"
 6     android:paddingBottom="@dimen/activity_vertical_margin"
 7     android:paddingLeft="@dimen/activity_horizontal_margin"
 8     android:paddingRight="@dimen/activity_horizontal_margin"
 9     android:paddingTop="@dimen/activity_vertical_margin"
10     tools:context="com.example.wang.testapp2.TestActivity7"
11     android:orientation="vertical">
12
13
14     <ListView
15         android:layout_width="match_parent"
16         android:layout_height="wrap_content"
17         android:id="@+id/lv_1" />
18 </LinearLayout>

ArrayAdapter.xml

1 <?xml version="1.0" encoding="utf-8"?>
2     <TextView xmlns:android="http://schemas.android.com/apk/res/android"
3     android:layout_width="match_parent"
4     android:layout_height="wrap_content"
5     android:textSize="20sp"
6     android:paddingTop="10dp"
7     android:paddingBottom="10dp"/>

arrayadapter.xml

 1 package com.example.wang.testapp2;
 2
 3 import android.support.v7.app.AppCompatActivity;
 4 import android.os.Bundle;
 5 import android.widget.ArrayAdapter;
 6 import android.widget.ListView;
 7
 8 public class TestActivity7 extends AppCompatActivity {
 9
10     ListView lv_1;
11
12     @Override
13     protected void onCreate(Bundle savedInstanceState) {
14         super.onCreate(savedInstanceState);
15         setContentView(R.layout.activity_test7);
16
17         ListView lv_1=(ListView)findViewById(R.id.lv_1);
18
19         //1.数据集合 Layout
20         String [] strings={"A1","A2","A3","A4","A5","A6","A7","A8","A9",
21                 "A1","A2","A3","A4","A5","A6","A7","A8","A9"};
22
23         //2.创建Adapter
24         ArrayAdapter<String>  arrayAdapter=new ArrayAdapter<String>(this,R.layout.array_adapter,strings);
25
26         //3.绑定到ListView
27         lv_1.setAdapter(arrayAdapter);
28
29     }
30 }

ArrayAdapter.java

时间: 2024-07-28 18:33:17

View(视图)——ListView之ArrayAdapter的相关文章

andorid 列表视图 ListView 之ArrayAdapter

activity_ui3.xml <?xml version="1.0" encoding="utf-8"?> <ListView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_p

列表视图ListView之一

在android开发中ListView是比较常用的组件,它以列表的形式展示具体内容,并且能够根据数据的长度自适应显示. 一.简单应用 1.打开"res/layout/activity_main.xml"文件. (1)从工具栏向activity拖出1个列表视图ListView. (2)打开activity_main.xml文件. 完整代码如下: <?xml version="1.0" encoding="utf-8"?><Rela

android笔记:ListView及ArrayAdapter

ListView用于展示大量数据,而数据无法直接传递给ListView,需要借助适配器adapter来完成. ArrayAdapter是最常用的adapter,可以通过泛型来指定要适配的数据类型. ArrayAdapter的参数如下: android.widget.ArrayAdapter.ArrayAdapter<String>(Context context, int textViewResourceId, String[] objects) 构造函数的参数解析如下: Context co

Android——列表视图 ListView(三)BaseAdapter

activity_activitybase.xml <?xml version="1.0" encoding="utf-8"?> <ListView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_pa

Android新手入门2016(8)--ListView之ArrayAdapter

本文来自肥宝传说之路,引用必须注明出处! ListView是Android中经常使用的控件. 什么是列表视图,让我们先看看图: 最常见的样例就是各种菜单的下啦列表. 要实现列表,须要完毕三个要素: 1.ListView 把全部的数据按指定的格式排成列表. 列表中每一项能够称为Item(如上图This is Title). 能够想象得出,要显示列表.就要先弄成相应的格式 2.adapter 适配器就是这样的ListView可以识别的格式,当然适配器有几种.以下再细说.适配器是指定格式的数据.可是我

列视图-Listview

如果程序需要显示不定数量的数据或者是动态变动的数据,比如联系人列表.相册,利用上一节的布局方式来实现将很不灵活,这种场景下最有效的展现视图是列表视图(ListView或Gridview).Listview和Gridview都继承自AbsListView,所以在使用上有类似的地方.下面具体介绍这两个视图的使用方法. Listview常用于展示一系列相似类型的数据,下面以一个简化的联系人列表来讲解Listview的基本用法. 主界面布局. main.xml 1.   <RelativeLayout

Android -- ListView与ArrayAdapter、SimpleAdapter

对于ArrayAdapter,里面虽然能添加图片,但只能是相同的图片. 废话不多说: 布局&&list的item布局                                                                 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.andro

Android列表视图ListView和ListActivity-android学习之旅(二十四)

ListView简介 ListView是android中常用的一种控件,创建ListView有两种方式: 1.在xml中使用ListView控件创建. 2.使用activity继承ListActivity,然后使用setListAdapter()创建,如果需要在xml中创建,需要android:id = @id:android:list Listview和GridView和Spinner和Gallery等Adapterview都是容器,用adapter来提供数据,而adapterView负责数据

Android train——ListView绑定ArrayAdapter、SimpleAdapter、SimpleCursorAdapter、BaseAdapter

ListView绑定ArrayAdapter res/layout/activity_main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout

Android学习-列表视图ListView

一.简介: ListView,列表视图,直接继承了AbsListView,是一个以垂直方式在项目中显示View视图的列表.ListView的数据项,来自一个继承了ListAdapter接口的适配器. 二.新建一个包listview并新建ListViewActivity.java活动: 12345678 public class ListViewActivity extends AppCompatActivity { @Override protected void onCreate(Bundle