SimpleAdapter是扩展性最好的适配器,可以定义各种你想要的布局,而且使用很方便。

layout :

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#7f00"    //分割线
android:dividerHeight="2dp"
android:id="@+id/listview_sample"/>
</LinearLayout>

header layout:

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher"/>
</LinearLayout>

自定义布局  item:

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3px"
android:id="@+id/img"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:id="@+id/title"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/info"
android:textSize="16sp"/>
</LinearLayout> </LinearLayout>

 

Java 代码:

 public class SampleAdapterActivity extends Activity {

     private ListView mListview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sampleadapter_layout);
mListview = (ListView) findViewById(R.id.listview_sample);
SimpleAdapter adapter = new SimpleAdapter(this,
getData(), //数据来源
R.layout.item_listview, //对应item view
new String[]{"img","title","info"}, //data 中对应值
new int[]{R.id.img,R.id.title,R.id.info}); //填充layout位置
mListview.setHeaderDividersEnabled(true); //是否显示头view 的分割线
View header = View.inflate(this,R.layout.listview_header,null);
View footer = View.inflate(this,R.layout.listview_header,null);
mListview.addHeaderView(header); //添加头部view
mListview.addFooterView(footer); //添加底部view
mListview.setAdapter(adapter);
} @Override
protected void onResume() {
super.onResume();
}
private List<? extends Map<String,?>> getData() {
List<Map<String,Object>> items = new ArrayList<Map<String, Object>>();
for (int i = 0; i < 5; i++) {
Map<String,Object> item = new HashMap<String,Object>();
item.put("img",R.mipmap.ic_launcher);
item.put("title","title -- " + i );
item.put("info","info -- " + i );
items.add(item);
}
return items;
}
}

显示效果

Android UI:ListView -- SimpleAdapter的更多相关文章

  1. Android UI ListView的使用

    一.ListView的理解  1.什么ListView?   一种用来显示多个可滑动项(Item)列表的的ViewGroup 需要使用Adapter将集合数据和每一个Item所对应的布局动态适配到Li ...

  2. [Android UI] listview 自定义style

    <style name="comm_listview_style"> <item name="android:cacheColorHint"& ...

  3. Android UI组件----ListView列表控件详解

    [声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/3 ...

  4. Android UI学习 - ListView (android.R.layout.simple_list_item_1是个什么东西)

    Android UI学习 - ListView -- :: 标签:Android UI 移动开发 ListView ListActivity 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始 ...

  5. Android -- ListView(SimpleAdapter) 自定义适配器

    aaarticlea/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBA ...

  6. 【Android】以SimpleAdapter做适配器的ListView和GridView

    SimpleAdapter介绍 SimpleAdapter是一个简单的适配器,可以将静态数据映射到XML文件中定义好的视图. 构造函数 public SimpleAdapter (Context co ...

  7. android UI进阶之实现listview的分页加载

    上篇博文和大家分享了下拉刷新,这是一个用户体验非常好的操作方式.新浪微薄就是使用这种方式的典型. 还有个问题,当用户从网络上读取微薄的时候,如果一 下子全部加载用户未读的微薄这将耗费比较长的时间,造成 ...

  8. Android UI组件----自定义ListView实现动态刷新

    [声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/3 ...

  9. android UI进阶之实现listview的下拉加载

    关于listview的操作五花八门,有下拉刷新,分级显示,分页列表,逐页加载等,以后会陆续和大家分享这些技术,今天讲下下拉加载这个功能的实现. 最初的下拉加载应该是ios上的效果,现在很多应用如新浪微 ...

随机推荐

  1. 前端学PHP之面向对象系列第四篇——关键字

    × 目录 [1]public [2]protected [3]private[4]final[5]static[6]const[7]this[8]self[9]parent 前面的话 php实现面向对 ...

  2. Rust初步(四):在rust中处理时间

    这个看起来是一个很小的问题,我们如果是在.NET里面的话,很简单地可以直接使用System.DateTime.Now获取到当前时间,还可以进行各种不同的计算或者输出.但是这样一个问题,在rust里面, ...

  3. OWIN 中 K Commands 与 OwinHost.exe 相等吗?

    OwinHost.exe: While some will want to write a custom process to run Katana Web applications, many wo ...

  4. DevExpress控件安装、汉化使用教程

    前言 DevExpress是一个庞大的控件库,也很是好用(没用过,听说),但是要收费. 网上关于DevExpress的教程满天飞,我找了一下午也没找到正确的安装.简单实用教程,还是自己摸索吧. 自己动 ...

  5. golang 字符串操作实例

    package main import s "strings" import "fmt" var p = fmt.Println func main() { p ...

  6. php左侧分类列表显示菜单

    <!DOCTYPE> <html> <head> <meta http-equiv="content-type" content=&quo ...

  7. 计时器StopWatch示例

    计时器 StopWatch stwatch = new StopWatch(getClass().getSimpleName()); try{ stwatch.start(joinPoint.getS ...

  8. swift 中数据类型那个的转换

    在swift中关于数据类型的转换,如果参数是可选类型? 那么打印或者转换的结果 会带有Optional 字样,,

  9. ssh整合问题总结--使用HibernateTemplate实现数据分页展示

    在进行大量的数据展示时,必须要使用分页查询,第一次使用在SSH框架整合中使用分页查询,遇到了一些问题,下面以我练习的项目为例详细介绍,如何在Spring+hibernate(+action)的环境下完 ...

  10. 【面试】shuffle函数的实现

    一.前言 有位同学面试的时候被问到shuffle函数的实现,他之后问我,我知道这个函数怎么用,知道是对数组(或集合)中的元素按随机顺序重新排列.但是没有深入研究这个是怎么实现的.现在直接进入JDK源码 ...