首先我们将listview简单实现,有图形,有文字:效果如图


之前我们完成了一个较为简单的listview视图列表,但是生活中我们往往碰到的

是更为复杂列表,有图像有评分标准,不如我们来试一试手,做一个琳琅满目的美团美食列表,在看的口水涟涟份上我们来实现它。

首先我们定义模板,也是第一次在安卓中接触模板概念,在layout里定义模板文件,data_list.xml

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. android:id="@+id/LinearLayout1"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:orientation="horizontal" >
  6. <ImageView
  7. android:id="@+id/pic"
  8. android:padding="3px"
  9. android:layout_width="wrap_content"
  10. android:layout_height="wrap_content"
  11. />
  12. <LinearLayout
  13. android:layout_width="200px"
  14. android:layout_height="wrap_content"
  15. android:gravity="left"
  16. android:orientation="vertical" >
  17. <TextView
  18. android:id="@+id/title"
  19. android:padding="3px"
  20. android:textSize="26px"
  21. android:layout_width="wrap_content"
  22. android:layout_height="wrap_content"
  23. android:text="TextView" />
  24. <TextView
  25. android:id="@+id/author"
  26. android:padding="3px"
  27. android:textSize="15px"
  28. android:layout_width="wrap_content"
  29. android:layout_height="wrap_content"
  30. android:text="TextView" />
  31. </LinearLayout>
  32. <LinearLayout
  33. android:layout_width="match_parent"
  34. android:layout_height="wrap_content"
  35. android:orientation="vertical" >
  36. <ImageView
  37. android:id="@+id/score"
  38. android:padding="5px"
  39. android:layout_width="wrap_content"
  40. android:layout_height="wrap_content"
  41. />
  42. <TextView
  43. android:id="@+id/type"
  44. android:padding="5px"
  45. android:layout_width="wrap_content"
  46. android:layout_height="wrap_content"
  47. android:text="TextView" />
  48. </LinearLayout>
  49. </LinearLayout>

也就是这样:

然后在main.xml布局文件定义:

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:tools="http://schemas.android.com/tools"
  3. android:id="@+id/LinearLayout1"
  4. android:layout_width="fill_parent"
  5. android:layout_height="fill_parent"
  6. android:orientation="vertical"
  7. android:paddingBottom="@dimen/activity_vertical_margin"
  8. android:paddingLeft="@dimen/activity_horizontal_margin"
  9. android:paddingRight="@dimen/activity_horizontal_margin"
  10. android:paddingTop="@dimen/activity_vertical_margin"
  11. tools:context=".MainActivity" >
  12. <TextView
  13. android:id="@+id/textView1"
  14. android:textSize="50px"
  15. android:gravity="center_horizontal"
  16. android:layout_width="wrap_content"
  17. android:layout_height="wrap_content"
  18. android:text="美食列表" />
  19. <ListView   //这里之后我们会把模板嵌入进去
  20. android:id="@+id/datalist"
  21. android:layout_width="fill_parent"
  22. android:layout_height="wrap_content" >
  23. </ListView>
  24. </LinearLayout>

以上的listview只是一个名字定义,我们建立好模板就可以代入进去,如何代入还是用Simpleadapter适配器,这部分实现要在MainActivity.java里实现,首先我们准备好几张美食图片,以及打分。

然后在代码里实现:

  1. public class MainActivity extends Activity {
  2. private int[] pic=new int[]{R.drawable.a1,R.drawable.a2,R.drawable.a3,R.drawable.a4
  3. ,R.drawable.a5,R.drawable.a6};
  4. private String data[][]=new String[][]{{"来御来三汁焖锅","烧烤烤肉"},{"SPK思必客麻辣香锅","烧烤烤肉"},
  5. {"冰果彩虹","蛋糕甜点"},{"德克士","小吃快餐"},{"老北京炸酱面","小吃快餐"},{"铁板传奇","其他美食"}};
  6. private List<Map<String,String>> list=new ArrayList<Map<String,String>>();
  7. private ListView datalist;
  8. private SimpleAdapter simpleadapter=null;
  9. protected void onCreate(Bundle savedInstanceState) {
  10. super.onCreate(savedInstanceState);
  11. setContentView(R.layout.activity_main);
  12. this.datalist=(ListView)super.findViewById(R.id.datalist);
  13. for(int i=0;i<data.length;i++){
  14. Map map=new HashMap<String,String>();
  15. map.put("pic", String.valueOf(this.pic[i]));
  16. map.put("title", this.data[i][0]);
  17. map.put("author",this.data[i][1]);
  18. map.put("score",String.valueOf(R.drawable.star) );
  19. map.put("type", "岳麓区天马");
  20. this.list.add(map);
  21. }
  22. this.simpleadapter=new SimpleAdapter(this,this.list,R.layout.data_list,
  23. new String[]{"pic","title","author","score","type"}
  24. ,new int[]{R.id.pic,R.id.title,R.id.author,R.id.score,R.id.type});
  25. this.datalist.setAdapter(this.simpleadapter);
  26. }
  27. @Override
  28. public boolean onCreateOptionsMenu(Menu menu) {
  29. // Inflate the menu; this adds items to the action bar if it is present.
  30. getMenuInflater().inflate(R.menu.main, menu);
  31. return true;
  32. }
  33. }

如同上节课一样,一一匹配,首先将图片之类的统统存入数组,数组统统存入map健和value值,然后将map存入list队列里面,然后加入到适配器里面进行分封装,然后ListView就坐享其成得到这个适配器。

然后我们的美团列表就冰果诞生了:


 

Android之listview运用(美团美食列表)的更多相关文章

  1. Android开发 ListView(垂直滚动列表项视图)的简单使用

    效果图: 使用方法: 1.在布局文件中加入ListView控件: <?xml version="1.0" encoding="utf-8"?> &l ...

  2. Android使用listView,BaseAdapter实现列表页

    参考: 1.讲解很详细: blog.csdn.net/psuaije/article/details/7447391 总结: 代码:

  3. 我的Android进阶之旅------>Android二级ListView列表的实现

    实现如下图所示的二级列表效果 首先是在布局文件中,布局两个ListView,代码如下: <LinearLayout xmlns:android="http://schemas.andr ...

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

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

  5. Android通过LIstView显示文件列表

    [绥江一百]http://www.sj100.net                                                  欢迎,进入绥江一百感谢点击[我的小网站,请大家多 ...

  6. 如何在Android的ListView中构建CheckBox和RadioButton列表(支持单选和多选的投票项目示例)

    引言 我们在android的APP开发中有时候会碰到提供一个选项列表供用户选择的需求,如在投票类型的项目中,我们提供一些主题给用户选择,每个主题有若干选项,用户对这些主题的选项进行选择,然后提交. 本 ...

  7. Android 自定义 ListView 上下拉动“刷新最新”和“加载更多”歌曲列表

    本文内容 环境 测试数据 项目结构 演示 参考资料 本文演示,上拉刷新最新的歌曲列表,和下拉加载更多的歌曲列表.所谓"刷新最新"和"加载更多"是指日期.演示代码 ...

  8. Android 自定义 ListView 显示网络上 JSON 格式歌曲列表

    本文内容 环境 项目结构 演示自定义 ListView 显示网络上 JSON 歌曲列表 参考资料 本文最开始看的是一个国人翻译的文章,没有源代码可下载,根据文中提供的代码片段,自己新建的项目(比较可恶 ...

  9. Android 使用ListView显示信息列表

    课程目标1.理解ListView的基础使用2.学会熟练运用两种适配器(ArrayAdapter.SimpleAdapter)3.学会熟练运用两种监听器(OnScrollListener.OnItemC ...

随机推荐

  1. Jquery中"$(document).ready(function(){ })"函数的使用详解

    Jquery是优秀的Javascrīpt框架,$是jquery库的申明,它很不稳定(我就常遇上),换一种稳定的写法jQuery.noConflict(); jQuery(document).ready ...

  2. mybatis自定义枚举转换类

    转载自:http://my.oschina.net/SEyanlei/blog/188919 mybatis提供了EnumTypeHandler和EnumOrdinalTypeHandler完成枚举类 ...

  3. Spring boot 各种入门及问题

    Spring boot 入门 整合(完整版): https://blog.csdn.net/winter_chen001/article/details/77249029 mybatis-genera ...

  4. 解决 IllegalArgumentException: Could not resolve placeholder in string value "${XXXXXX}"

    如题: 导致这一问题的原因:使用了重复的property-placeholder 如一个配置文件中使用了 <context:property-placeholder location=" ...

  5. 微信小程序 - 日期(起止)选择器组件

    2019-01-03 : 修复了日期day-1,新增了年月日(除去时分秒),删除了不必要的touchmove 新增: column: ""(年月日) 配置: pickerConfi ...

  6. 013-Go通archive/zip生成ZIP文件

    package main import( "io/ioutil" "os" "bytes" "archive/zip" ...

  7. bootstrap设计站点中加入代码高亮插件

    这款插件的名字叫做google-code-prettify 使用该插件之前的效果: 使用插件之后的效果: 接下来说步骤: (1)下载两个文件 http://codecloud.sinaapp.com/ ...

  8. BIEE Demo(RPD创建 + 分析 +仪表盘 )

    说明:此Demo步骤简略,详细Demo可以参照下面的 天善视频:BIEE 11G Rpd模型设计 天善视频:BIEE 11G 报表开发 Oracle BIEE (Business Intelligen ...

  9. 查看MySQL的当前日期

    select current_date(); 查看MySQL的当前日期

  10. CString与UTF8互转代码

    这个代码网上很多,留在这里做个备份. static std::string ConvertCStringToUTF8( CString strValue ) { std::wstring wbuffe ...