ListView

作用: 1.将数据填充到布局。 2.处理用户的选择点击等操作。

根据列表的适配器类型,列表分为三种,ArrayAdapter,SimpleAdapter和SimpleCursorAdapter

实例:listview.xml

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:descendantFocusability="afterDescendants">

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:cacheColorHint="#00000000"

android:dividerHeight="1dp"

android:divider="#FF0000"

/>item.xml

android:layout_width="match_parent"

android:layout_height="match_parent"

android:gravity="center_vertical"

android:orientation="horizontal">

android:layout_width="100dp"

android:layout_height="100dp"

android:layout_marginLeft="15dp"

android:class="lazyload" src="https://img-blog.csdnimg.cn/2022010700564781686.png" data-original="@drawable/a2"/>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="25dp"/>

public class ActivityListView extends Activity {   private ListView mListView;   protected void onCreate(android.os.Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        //加载listview控件所在的布局文件        setContentView(R.layout.listview_layout);        //获取listview控件的对象

mListView = (ListView)findViewById(R.id.listview);        /**

*定义SimpleAdapter(并加载对应item布局文件,获得对应的keY,获得对应item布局文件中的组件的id

*第二个参数data:数据源第三个参数resource:listView每个item对应的布局文件第四个参数 from:

*第五个参数to: new String[]{对应的key}v         */

SimpleAdapter simpleAdapter =new SimpleAdapter(this, get_data(),

R.layout.item_listview,new String[]{"name","img" },

newint[] { R.id.txtname, R.id.img });             //通过setAdapter将适配器绑定到listView控件              mListView.setAdapter(simpleAdapter);

};        /**

*数据源          */

String[] name = { "张三","李四","小星星","静静","明明","小翠" };         private ArrayList> get_data() {         //定义一个ArrayList的集合(集合中又封装一个map类型的集合)

ArrayList> data_list =new ArrayList>();               for (int i = 0; i

Map data_map =new HashMap();

data_map.put("name",name[i]);

data_map.put("img",R.drawable.a1);                  //将map集合添加(封装)到ArrayList集合中                 data_list.add(data_map);

}             //返回ArrayList集合

return data_list;

}

}

Gallery

作用:实现图片计时滚动显示

gallery.xml

android:layout_width="match_parent"

android:layout_height="match_parent"

android:gravity="center_vertical"

android:orientation="vertical">

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:spacing="0dip"/>

public class ActivityGrelly extends Activity {   /** Called when the activity isfirst created. */

private int index;   private Gallery g;   private Handler handler;   public void onCreate(Bundle savedInstanceState) {      super.onCreate(savedInstanceState);

setContentView(R.layout.gallery_layout);

initView();

}

private void initView() {      // TODOAuto-generated method stub      // 获得Gallery对象

g = (Gallery)findViewById(R.id.gallery);

// 添加ImageAdapter给Gallery对象

g.setAdapter(newImageAdapter(this));

// 设置Gallery的背景      g.setBackgroundResource(R.drawable.bg);

TimerTask task = new TimerTask() {

@Override         public void run() {

Message message = new Message();

message.what = 2;

index = g.getSelectedItemPosition();

index++;

handler.sendMessage(message);

}

};

Timer timer = new Timer();

timer.schedule(task, 3000, 3000);

handler = new Handler(){

@Override         public void handleMessage(Message msg) {            super.handleMessage(msg);            switch (msg.what) {            case 2:

g.setSelection(index);                break;

default:                break;

}

}

};

// 设置Gallery的事件监听

g.setOnItemClickListener(new OnItemClickListener() {         public void onItemClick(AdapterView> parent, View v,                int position,long id) {

Toast.makeText(ActivityGrelly.this,                   "你选择了" + (position + 1) +"号图片", Toast.LENGTH_SHORT)

.show();

}

});

}

}

android 图片列表,Android 列表使用(ListView GridView Gallery图片计时滚动)相关推荐

  1. android之ListView和adapter配合显示图片和文字列表

    listView页面布局:layout/activity_main.xml: <LinearLayout xmlns:android="http://schemas.android.c ...

  2. android 列表上拉加载更多,Android 下拉刷新,上拉加载更多控件–支持ListView,GridView和ScrollView...

    麦洛遇到这样一个需求,实现类似于IOS下拉刷新,上拉加载更多的控件.麦洛google,baidu了一番,网上有不少实现,比较常见的是国外牛人的实现,不过国外的实现基本上都是扩展于ListView,所以 ...

  3. Android学习系列(10)--App列表之拖拽ListView(上)

    研究了很久的拖拽ListView的实现,受益良多,特此与尔共飨.       鉴于这部分内容网上的资料少而简陋,而具体的实现过程或许对大家才有帮助,为了详尽而不失真,我们一步一步分析,分成两篇文章. ...

  4. Android应用--简、美音乐播放器获取专辑图片(自定义列表适配器)

    Android应用--简.美音乐播放器获取专辑图片(自定义列表适配器) 2013年7月3日简.美音乐播放器开发 第二阶段已增加功能: 1.歌词滚动显示 2.来电监听 3.音量控制 4.左右滑动切换歌词 ...

  5. Android带标题的列表,Listview Section 多个标题以及内容

    其中日期标题部分视图布局: view sourceprint?1 <?xml version="1.0″ encoding="utf-8″?> android:orie ...

  6. Carson带你学Android:全面解析列表ListView与AdapterView

    前言 ListView在Android开发中十分常见 今天,我将为大家带来ListView与AdapterView全面解析,含其特点.工作原理等,希望你们会喜欢. Carson带你学Android系列 ...

  7. android列表项点击事件,Android 开发 tips(2):监听 Listview 列表项点击事件

    Android 开发 tips(2):监听 Listview 列表项点击事件 (这篇和上篇本来是应该一起写的,但是太过冗长,附链接:[SimpleAdapter 在 Listview 中的应用] ht ...

  8. Android学习系列(11)--App列表之拖拽ListView(下)

    接着上篇Android学习系列(10)--App列表之拖拽ListView(上)我们继续实现ListView的拖拽效果. 7.重写onTouchEvent()方法.      在这个方法中我们主要是处 ...

  9. android 实现QQ好友列表(扩展listview:ExpandableListView)

    在某些android开发群里,看到有些新手问怎么实现QQ好友列表,其实网上一搜挺多的.接触Android,也才一年的时间,大部分时间花在工作上(解bug...),界面上开发很少参与.自己维护的系统应用 ...

最新文章

  1. 7.Mongodb复制(副本集)
  2. 人工智能即服务 当人工智能遇到云计算
  3. 全球数百万台 Mac 疑似因 Big Sur 更新险酿计算灾难,苹果官方回应来了!
  4. Flask | 浅读文档,快速出发
  5. 关于easyui的layout的region的resize的问题(自适应浏览器)
  6. Android L 的 Tint(着色)
  7. 用eclipse配置spket编写extjs代码方法
  8. 散点图 横纵坐标_厉害了我的Python!散点图还能这么画
  9. spring核心包功能解析
  10. 木兰许可证专业解读及首批采用“木兰”开源项目列表
  11. 计算机应用与推广,计算机在中小学教学中的推广和应用
  12. Apache Arrow 内存数据
  13. 编译安装libmemcached库报错
  14. 获取表结构信息(字段名,类型,长度,精度,小数位数,主键,自动增长)...
  15. Axis2发布webservices
  16. Struts框架(一)
  17. python矩阵行秩函数_矩阵的秩的性质以及矩阵运算和矩阵的秩的关系
  18. alpha-beta剪枝算法原理(附代码)
  19. 【西瓜书】决策树ID3算法
  20. App Store 受欢迎榜单(美国区)-分析出未来方向

热门文章

  1. 如何在golang中关闭bufio.reader_Golang 并发模型系列:1. 轻松入门流水线模型
  2. Bio+IT 爱好者社区,欢迎你!
  3. 在线作图|如何绘制一张星图
  4. 牛!王军等喜提NBT:用AI在肠道超高效“挖”抗菌肽(附独家专访) | 热心肠日报...
  5. Microbiome:应用多维宏组学方法协同揭示复杂细菌群落对目标底物代谢的菌间相互关系(一作解读)...
  6. COM:微生物促进植物的氮获得
  7. ggplot2笔记5:通过图层构建图像
  8. 三线表是什么?R语言使用table1包绘制(生成)三线表、使用单变量分列构建三线表、编写自定义三线表结构(将因子变量细粒度化重新构建三线图)、编写自定义函数在三线表中添加p值
  9. python使用matplotlib可视化线图(line plot)、设置X轴坐标的下限和上限数值(setting the lower and upper bound of the x axis)
  10. pandas使用groupby函数对dataframe进行分组统计、使用as_index参数设置分组聚合的结果中分组变量不是dataframe的索引(index)