一、 ArrayAdapter

  ListView listView = (ListView) findViewById(R.id.list_view);//ListView的参数为id

  listView.setAdapter(new ArrayAdapter<Person>(this, android.R.layout.simple_list_item_1, list));//对象是Person,第一个参数是context,第二个是指代要显示的模版,最后一个是要显示的数据,list为person类的ArrayList集合。

二、 BaseAdapter

  、一行一行的显示对象

  ①、定义MyAdapter来继承BaseAdapter

   class MyAdapter extends BaseAdapter {

      @Override
      public int getCount() {
        return list.size();//list为person对象的List
      }       @Override
      public Object getItem(int position) {
        return null;
      }       @Override
      public long getItemId(int position) {
        return ;
      }       /**
      * 缓存的是被遮住的那一行
      */
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {         TextView textview = null;         if (null != convertView) {
        textview = (TextView) convertView;
        } else {
        textview = new TextView(MainActivity.this);
        }         textview.setText(list.get(position).toString());         return textview;
      }    }    ②、设置适配器     ListView listview = (ListView) findViewById(R.id.list_view);      listview.setAdapter(new MyAdapter());   、自定义一个xml,加入到ListView中再一行一行显示     ①、定义自己的要显示的一行的内容布局文件----list_item.xml     ②、定义MyAdapter来继承BaseAdapter         class MyAdapter extends BaseAdapter
    {       @Override
      public int getCount() {
        return list.size();
      }       @Override
      public Object getItem(int position) {
        return null;
      }       @Override
      public long getItemId(int position) {
        return ;
      }       @Override
      public View getView(int position, View convertView, ViewGroup parent) {
        //布局转换器 作用就是讲一个布局转换为一个对象
        LayoutInflater flater = MainActivity1.this.getLayoutInflater();
        View view = flater.inflate(R.layout.list_item, null); //真正将一个布局文件转为一个对象
        //在一个特定的对象上去查找一个ID所对应的组件
        TextView text_name = (TextView) view.findViewById(R.id.list_view_name);
        TextView text_age = (TextView) view.findViewById(R.id.list_view_age);
        Person person = list.get(position);
        text_name.setText(person.getName());
        text_age.setText(String.valueOf(person.getAge()));
        return view;
      }
    }   ③、设置适配器      ListView listview = (ListView) findViewById(R.id.list_view);      listview.setAdapter(new MyAdapter()); 三、SimpleAdapter,显示的一行内容里面包含多行数据   ①、定义自己的要显示的一行中要显示的多行的布局文件----list_item.xml   ②、设置适配器(代码的意思是要显示的多行xml中是一行name,一行age);       ListView listview = (ListView) findViewById(R.id.list_view);     List<Map<String, String>> data = new ArrayList<Map<String, String>>();     Map<String, String> info = new HashMap<String, String>();
    info.put("name", "zs");
    info.put("age", "");     data.add(info);     info = new HashMap<String, String>();
    info.put("name", "wangwu");
    info.put("age", "");
    data.add(info);     info = new HashMap<String, String>();
    info.put("name", "wangwu");
    info.put("age", "");
    data.add(info);     info = new HashMap<String, String>();
    info.put("name", "wangwu");
    info.put("age", "");
    data.add(info);     info = new HashMap<String, String>();
    info.put("name", "wangwu");
    info.put("age", "");
    data.add(info);     info = new HashMap<String, String>();
    info.put("name", "wangwu");
    info.put("age", "");
    data.add(info);     SimpleAdapter simple = new SimpleAdapter(this, data,
    R.layout.list_item, new String[] { "name", "age" }, new int[] {
    R.id.list_view_name, R.id.list_view_age });     listview.setAdapter(simple);

listview的两种适配器的更多相关文章

  1. (转载) Android-Spinner的使用以及两种适配器

    目录视图 摘要视图 订阅 赠书 | 异步2周年,技术图书免费选      程序员8月书讯      项目管理+代码托管+文档协作,开发更流畅 Android-Spinner的使用以及两种适配器 201 ...

  2. ListView+CheckBox两种解决方式及原因分析

    近期在用ListView+CheckBox搞一个item选中的项目,我将CheckBox的focus设置为false,另我大喜的是,CheckBox居然能够选中(窃喜中),这么简单就搞定了,由于数据量 ...

  3. 【Android自学日记】两种适配器的使用

    ArrayAdapter适配器: (1)用于显示基本的文字内容 (2)基本使用过程:新建适配器---创建或加载数据源---适配器加载数据源---视图加载适配器 ArrayAdapter(上下文,当前L ...

  4. Android ListView两种长按弹出菜单方式

    转自:http://www.cnblogs.com/yejiurui/p/3247527.html package com.wyl.download_demo; import java.util.Ar ...

  5. Android中通过数组资源文件xml与适配器两种方式给ListView列表视图设置数据源

    场景 实现效果如下 注: 博客: https://blog.csdn.net/badao_liumang_qizhi 关注公众号 霸道的程序猿 获取编程相关电子书.教程推送与免费下载. 实现 将布局改 ...

  6. 一个ListView怎么展示两种样式

    private class MyBaseMsgAdapter extends BaseAdapter { //获取数据适配器中条目类型的总数,修改成两种(纯文本,输入+文字) @Override pu ...

  7. 几种适配器&观察者&ListView之间的那点事

    android中的几种适配器&观察者&ListView 1.我们知道Android中的Adapter类是处于ListView和数据源之间的数据总线,它负责为ListView提供数据. ...

  8. 我的Android进阶之旅------>Android Listview跳到指定条目位置的两种实现方法

    前言 今天实现ListView跳转到第一个条目位置时,使用smoothScrollToPosition(int position)方法跳转实现了,但是交互说不需要这样的动画效果,需要直接跳转到第一项, ...

  9. Android一个ListView列表之中插入两种不同的数据

    http://www.cnblogs.com/roucheng/ Android一个ListView列表之中插入两种不同的数据 代码如下: public class ViewHolder{ Butto ...

随机推荐

  1. linux 之awk命令详解

    awk是一种程序语言,对文档资料的处理具有很强的功能.awk名称是由它三个最初设计者的姓氏的第一个字母而命名的: Alfred V. Aho.Peter J. We i n b e rg e r.Br ...

  2. startActivityForResult( )用法

    一.与startActivity( )的不同之处 1, startActivity( ) 仅仅是跳转到目标页面,若是想跳回当前页面,则必须再使用一次startActivity( ). 2, start ...

  3. JS高级语法与JS选择器

    元素(element)和节点(node) childNode属性和children属性的区别 <!DOCTYPE html> <html lang="en"> ...

  4. BZOJ5293: [Bjoi2018]求和 树上差分

    Description master 对树上的求和非常感兴趣.他生成了一棵有根树,并且希望多次询问这棵树上一段路径上所有节点深度的k  次方和,而且每次的k 可能是不同的.此处节点深度的定义是这个节点 ...

  5. 微信网页跳转页面常见bug处理

    微信网页跳转页面常见bug处理 1.不要直接用a链接直接跳转 2.url后加上时间戳 function gohome() { window.location.href = "../home/ ...

  6. SPOJ - INTSUB 数学

    题目链接:点击传送 INTSUB - Interesting Subset no tags  You are given a set X = {1, 2, 3, 4, … , 2n-1, 2n} wh ...

  7. mybatis generator插件系列--lombok插件 (减少百分之九十bean代码)

    经常使用mybatis generator生成代码的你 有没有因为生成的getter/setter而烦恼呢? 有没有生成后又手动加toString/hashCode/Equals方法呢? 有没有改一个 ...

  8. JavaScript中对象数组 作业题目以及作业

    var BaiduUsers = [], WechatUsers = []; var User = function(id, name, phone, gender, age, salary) { t ...

  9. Lua面向对象 --- 封装

    工程结构: Player.lua: Player = {} function Player:new() local self = {} setmetatable(self, {__index = Pl ...

  10. Python 爬虫-正则表达式(补)

    2017-08-08 18:37:29 一.Python中正则表达式使用原生字符串的几点说明 原生字符串和普通字符串的不同 相较于普通字符串,原生字符串中的\就是反斜杠,并不表达转义.不过,字符串转成 ...