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. Android Studio 入门级教程(三):gradle项目构建

    声明 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/4456420.html [系列] Andr ...

  2. #JS 前端javascript规范文档

    一.规范目的 为提高团队协作效率,便于前端后期优化维护,输出高质量的文档. 二.基本准则 符合web标准,结构表现行为分离,兼容性优良.页面性能方面,代码要求简洁明了有序, 尽可能的减小服务器负载,保 ...

  3. ClouderaManager中Event Server报No such file or directory

    错误日志如下: 2015-06-24 06:13:10,176 ERROR com.cloudera.cmf.eventcatcher.server.EventCatcherService: Erro ...

  4. SET操作符

    一:MySQL交集INTERSECT运算符 1.介绍 INTERSECT运算符是一个集合运算符,它只返回两个查询或更多查询的交集. 语法: INTERSECT运算符比较两个查询的结果,并返回由左和右查 ...

  5. Laravel 去掉访问后面的 “public”

    将laravel/server.PHP 改名为index.php,再将public目录下的.htaccess拷贝到Larvael根目录下,再访问Larvael就会发现不需要加上public,由于访问入 ...

  6. Python3之turtle模块的使用

    Python3之turtle模块的使用     直接扣代码就行: import turtle as t t.pensize(4) t.hideturtle() t.colormode(255) t.c ...

  7. svn+apache

    参考文章:http://www.ttlsa.com/svn/apache-svn-configure/ http://blog.csdn.net/huangshaotian/article/detai ...

  8. wdatepicker默认时间为当前时间

    $(document).ready(function() { alert(today()); document.getElementById("serviceTime").valu ...

  9. SDC信息统计分析系统ETL工具的研究与实现[专业:计算机应用技术]

    SDC信息统计分析系统ETL工具的研究与实现[专业:计算机应用技术] http://www.docin.com/p-265530271.html

  10. jsp的9大内置对象和4大作用域