ArrayAdapter是一个简单的适配器,他的作用是将一个数组中的内容放入listView中。listView的item必须为textView。

MainActivity.java

 package com.kale.listview;

 import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView; public class MainActivity extends Activity { ListView redLv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); redLv = (ListView)findViewById(R.id.red_listView_id); String []arr01 = {"01","02","03","04","05","06"};
//将数组送入arrayAdapter,这里的item对象必须是一个textView。
//系统已经默认将数组中的信息放入textView了,所以无需指定额外的id
ArrayAdapter<String> adapter01 = new ArrayAdapter<String>(this, R.layout.list_item,arr01);
//设置adapter
redLv.setAdapter(adapter01);
}
}

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_height="match_parent"
android:orientation="vertical" > <!-- 设置红色分割线的listView -->
<ListView
android:id="@+id/red_listView_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#f00"
android:dividerHeight="2dp"
android:layout_gravity="center"
android:headerDividersEnabled="false"/> </LinearLayout>

listview_item.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/item_textView_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Large Text"
android:gravity="center_horizontal"
android:textAppearance="?android:attr/textAppearanceLarge" />

 

ArrayAdapter使用方法的更多相关文章

  1. 注意ArrayAdapter的Add()方法

    ArrayAdapter类可以作为ListView等的适配器资源,并且可以动态向适配器中添加新的数据,这就是ArrayAdapter.Add()方法的作用.但是在使用该方法时如果出错,那就需要检查Ar ...

  2. 【原创】Android ExpandableListView使用

    ExpandableView的使用可以绑定到SimpleExpandableListAdapter,主要是看这个Adapter怎么用. 这个类默认的构造函数有9个参数, 很好地解释了什么叫做又臭又长. ...

  3. Android_常用控件及适配器

    TextView 控件中显示的内容必须是文本 TextView中常用的属性 android:text TextView中显示的文本内容 android:textColor 字体颜色 格式为#RGB # ...

  4. javaSE27天复习总结

    JAVA学习总结    2 第一天    2 1:计算机概述(了解)    2 (1)计算机    2 (2)计算机硬件    2 (3)计算机软件    2 (4)软件开发(理解)    2 (5) ...

  5. 关于ArrayAdapter的getCount()的方法会造成空指针异常的分析

    在继承了ArrayAdapter重新getCount()的方法后,比如 public int getCount() { return 3; } 若在活动中调用setAdapter()的方法前,List ...

  6. Android ArrayAdapter,BaseAdapter,SimpleAdapter适配器绑定数据方法

    /** * 2017-07-31.Book 类 */ public class Book { public String getName() { return name; } public void ...

  7. ArrayAdapter

    Android Adapter:ArrayAdapter篇 版权声明:本文为博主原创文章,未经博主允许不得转载.微博:厉圣杰源码:AndroidDemo/Notification文中如有纰漏,欢迎大家 ...

  8. Android应用项目中BaseAdapter、SimpleAdapter和ArrayAdapter中的三种适配器

    一.写在前面: 本次我们来讲解一下Android应用中三个适配器:BaseAdapter.SimpleAdapter和ArrayAdapter.其中常见的是BaseAdapter,也是个人推荐使用的适 ...

  9. Android ListView ArrayAdapter 的简单使用

    前面写了3篇关于android的文章,其中的演示程序都写在了一个工程中,当时为了方便测试就在启动页MainActivity中放了3个按钮,点击不同的按钮进入不同的示例程序页面,MainActivity ...

随机推荐

  1. linux系统下创建lvm挂载到指定目录

    1 .背景 在企业中有时我们为方便安装软件.数据的管理,需要把安装软件.数据放到固定目录下,磁盘满了方便扩展,这里假如需要一个/data目录存放数据,并单独进行挂载. 2.操作步骤 2.1  划分磁盘 ...

  2. 【AtCoder】ARC091

    C - Flip,Flip, and Flip...... 只有一个这一个是反面 只有一行那么除了两边以外都是反面 否则输出\((N - 2)*(M - 2)\) #include <bits/ ...

  3. MATLAB遍历文件夹下所有文件

    先给出函数 function [ files ] = scanDir( root_dir ) files={}; if root_dir(end)~='/' root_dir=[root_dir,'/ ...

  4. MySQL数据库之触发器

    1 引言 本文是对MySQL中触发器的总结,从触发器概念出发,结合实例对创建触发器.使用触发器.删除触发器进行介绍. 2 触发器简介 MySQL触发器和存储过程一样,都是嵌入到MySQL的一段程序.触 ...

  5. [转]LCT讲解

    LCT (1)维护一个序列,支持下列操作: 区间求和 区间求最值 区间修改 求连续子段和 这个线段树就可以解决 具体做法不加累述了 (2)维护一个序列,支持下列操作: 区间求和 区间求最值 区间修改 ...

  6. 关于dubbo服务的xml配置文件报错的问题

    在配置dubbo服务的过程中,经常会遇到虽然程序能够跑起来,但是配置文件一堆红叉,虽然不影响功能,但是确实很让人恶心. 报错信息如下: Multiple annotations found at th ...

  7. DMA Stream/Channel Outputting via GPIOC[0..7]

    Ok, so quickly mashing up another example using a different TIM, DMA Stream/Channel for illustration ...

  8. Eclipse Mark Occurrences

    Mark Occurrences The Mark Occurrences feature enables you to see where an element is referenced by s ...

  9. js判断只能输入数字或小数点

    JS判断只能是数字和小数点 1.文本框只能输入数字代码(小数点也不能输入) <input onkeyup="this.value=this.value.replace(/\D/g,'' ...

  10. Revit API布置卫浴装置

    //放置卫浴装置 [Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)] public clas ...