Android之listview运用(美团美食列表)
首先我们将listview简单实现,有图形,有文字:效果如图


之前我们完成了一个较为简单的listview视图列表,但是生活中我们往往碰到的
是更为复杂列表,有图像有评分标准,不如我们来试一试手,做一个琳琅满目的美团美食列表,在看的口水涟涟份上我们来实现它。
首先我们定义模板,也是第一次在安卓中接触模板概念,在layout里定义模板文件,data_list.xml
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/LinearLayout1"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="horizontal" >
- <ImageView
- android:id="@+id/pic"
- android:padding="3px"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- />
- <LinearLayout
- android:layout_width="200px"
- android:layout_height="wrap_content"
- android:gravity="left"
- android:orientation="vertical" >
- <TextView
- android:id="@+id/title"
- android:padding="3px"
- android:textSize="26px"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="TextView" />
- <TextView
- android:id="@+id/author"
- android:padding="3px"
- android:textSize="15px"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="TextView" />
- </LinearLayout>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical" >
- <ImageView
- android:id="@+id/score"
- android:padding="5px"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- />
- <TextView
- android:id="@+id/type"
- android:padding="5px"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="TextView" />
- </LinearLayout>
- </LinearLayout>
也就是这样:
然后在main.xml布局文件定义:
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:id="@+id/LinearLayout1"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="vertical"
- android:paddingBottom="@dimen/activity_vertical_margin"
- android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- tools:context=".MainActivity" >
- <TextView
- android:id="@+id/textView1"
- android:textSize="50px"
- android:gravity="center_horizontal"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="美食列表" />
- <ListView //这里之后我们会把模板嵌入进去
- android:id="@+id/datalist"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content" >
- </ListView>
- </LinearLayout>
以上的listview只是一个名字定义,我们建立好模板就可以代入进去,如何代入还是用Simpleadapter适配器,这部分实现要在MainActivity.java里实现,首先我们准备好几张美食图片,以及打分。
然后在代码里实现:
- public class MainActivity extends Activity {
- private int[] pic=new int[]{R.drawable.a1,R.drawable.a2,R.drawable.a3,R.drawable.a4
- ,R.drawable.a5,R.drawable.a6};
- private String data[][]=new String[][]{{"来御来三汁焖锅","烧烤烤肉"},{"SPK思必客麻辣香锅","烧烤烤肉"},
- {"冰果彩虹","蛋糕甜点"},{"德克士","小吃快餐"},{"老北京炸酱面","小吃快餐"},{"铁板传奇","其他美食"}};
- private List<Map<String,String>> list=new ArrayList<Map<String,String>>();
- private ListView datalist;
- private SimpleAdapter simpleadapter=null;
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- this.datalist=(ListView)super.findViewById(R.id.datalist);
- for(int i=0;i<data.length;i++){
- Map map=new HashMap<String,String>();
- map.put("pic", String.valueOf(this.pic[i]));
- map.put("title", this.data[i][0]);
- map.put("author",this.data[i][1]);
- map.put("score",String.valueOf(R.drawable.star) );
- map.put("type", "岳麓区天马");
- this.list.add(map);
- }
- this.simpleadapter=new SimpleAdapter(this,this.list,R.layout.data_list,
- new String[]{"pic","title","author","score","type"}
- ,new int[]{R.id.pic,R.id.title,R.id.author,R.id.score,R.id.type});
- this.datalist.setAdapter(this.simpleadapter);
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.main, menu);
- return true;
- }
- }
如同上节课一样,一一匹配,首先将图片之类的统统存入数组,数组统统存入map健和value值,然后将map存入list队列里面,然后加入到适配器里面进行分封装,然后ListView就坐享其成得到这个适配器。
然后我们的美团列表就冰果诞生了:


Android之listview运用(美团美食列表)的更多相关文章
- Android开发 ListView(垂直滚动列表项视图)的简单使用
效果图: 使用方法: 1.在布局文件中加入ListView控件: <?xml version="1.0" encoding="utf-8"?> &l ...
- Android使用listView,BaseAdapter实现列表页
参考: 1.讲解很详细: blog.csdn.net/psuaije/article/details/7447391 总结: 代码:
- 我的Android进阶之旅------>Android二级ListView列表的实现
实现如下图所示的二级列表效果 首先是在布局文件中,布局两个ListView,代码如下: <LinearLayout xmlns:android="http://schemas.andr ...
- Android一个ListView列表之中插入两种不同的数据
http://www.cnblogs.com/roucheng/ Android一个ListView列表之中插入两种不同的数据 代码如下: public class ViewHolder{ Butto ...
- Android通过LIstView显示文件列表
[绥江一百]http://www.sj100.net 欢迎,进入绥江一百感谢点击[我的小网站,请大家多 ...
- 如何在Android的ListView中构建CheckBox和RadioButton列表(支持单选和多选的投票项目示例)
引言 我们在android的APP开发中有时候会碰到提供一个选项列表供用户选择的需求,如在投票类型的项目中,我们提供一些主题给用户选择,每个主题有若干选项,用户对这些主题的选项进行选择,然后提交. 本 ...
- Android 自定义 ListView 上下拉动“刷新最新”和“加载更多”歌曲列表
本文内容 环境 测试数据 项目结构 演示 参考资料 本文演示,上拉刷新最新的歌曲列表,和下拉加载更多的歌曲列表.所谓"刷新最新"和"加载更多"是指日期.演示代码 ...
- Android 自定义 ListView 显示网络上 JSON 格式歌曲列表
本文内容 环境 项目结构 演示自定义 ListView 显示网络上 JSON 歌曲列表 参考资料 本文最开始看的是一个国人翻译的文章,没有源代码可下载,根据文中提供的代码片段,自己新建的项目(比较可恶 ...
- Android 使用ListView显示信息列表
课程目标1.理解ListView的基础使用2.学会熟练运用两种适配器(ArrayAdapter.SimpleAdapter)3.学会熟练运用两种监听器(OnScrollListener.OnItemC ...
随机推荐
- Install Hyper-V on Windows 10
Enable Hyper-V to create virtual machines on Windows 10.Hyper-V can be enabled in many ways includ ...
- Ant编译utf-8非法字符:/65279 解决方法
原文链接:http://blog.csdn.net/xiyuan1999/article/details/5989336 Ant编译utf-8非法字符:/65279 解决方法 使用ant编译j ...
- codeforces 551 C GukiZ hates Boxes
--睡太晚了. ..脑子就傻了-- 这个题想的时候并没有想到该这样-- 题意大概是有n堆箱子从左往右依次排列,每堆ai个箱子,有m个人,最開始都站在第一个箱子的左边, 每个人在每一秒钟都必须做出两种选 ...
- js文件流下载通用方法
通常我们会用到文件流下载文件,下面给大家一个通用的文件流下载的js /* *下载文件 * options:{ * url:'', //下载地址 * isNewWinOpen:false,是否新窗口打开 ...
- ecshop二次开发 使用ecshop电子商务系统的100个小问题
自己从事B4C电子商务开发一段时间了,特别对ecshop深有体会,刚接触的时候不容易理解,下面将根据自己的经验,来总结100条关于操作ecshop电子商务系统的小问题. 1:如何修改网站"欢 ...
- 详解使用DockerHub官方的mysql镜像生成容器
详解使用DockerHub官方的mysql镜像生成容器 收藏 yope 发表于 10个月前 阅读 1506 收藏 32 点赞 1 评论 0 腾讯云·云上实验室:开发者零门槛,免费使用真机在线实验!&g ...
- Solidworks直接打开SWB文件报错怎么办
- 整理收集49条JQuery代码小结
1. 如何创建嵌套的过滤器 . 代码如下: //允许你减少集合中的匹配元素的过滤器, //只剩下那些与给定的选择器匹配的部分.在这种情况下, //查询删除了任何没(:not)有(:has) //包含c ...
- 牛客网-《剑指offer》-替换空格
题目:http://www.nowcoder.com/practice/4060ac7e3e404ad1a894ef3e17650423 C++ class Solution { public: vo ...
- 017-通过govendor管理依赖包
1:安装 go get -u github.com/kardianos/govendor 2:配置环境变量 需要把 $GOPATH/bin/ 加到 PATH 中 D:\my_workspace\go_ ...