每次写listview都要翻以前的代码,好烦。所以记下模板,方便下次的使用。

  xml文件部分代码:

         <ListView
android:id="@+id/listview"
android:scrollingCache="false"
android:cacheColorHint="#00000000"
android:divider="@null"
android:listSelector="@android:color/transparent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fadingEdge="none"
android:fadeScrollbars="true">
</ListView>

item的xml布局:(listview_style.xml)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content"
android:layout_height="wrap_content"> <TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="abcd"
/> </RelativeLayout>

java 代码:

    定义:
   private ListView m_Listview;
private MyAdapter m_listAdapter;
private List<Map<String, String>> m_dataList = new ArrayList<Map<String, String>>();
  
初始化:
   

m_listAdapter = new MyAdapter(this,m_dataList);
       m_Listview = (ListView) findViewById(R.id.listview);
       m_Listview.setAdapter(m_listAdapter);
       m_listAdapter.notifyDataSetChanged();


   自定义适配器:
class MyAdapter extends BaseAdapter{
private Context m_context; //运行上下文
private List<Map<String, String>> m_MapItems ;
private LayoutInflater m_listContainer; //视图容器 public final class ListItemView{ //自定义控件集合
TextView tv;
} public MyAdapter (Context context ,List<Map<String, String>> MapItems) { // TODO Auto-generated constructor stub
this.m_context = context;
m_listContainer = LayoutInflater.from(context); //创建视图容器并设置上下文
this.m_MapItems = MapItems;
} @Override
public int getCount() {
// TODO Auto-generated method stub
return m_MapItems.size();
} @Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return m_MapItems.get(position);
} @Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
} @Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub ListItemView listItemView = null;
if (convertView == null) {
listItemView = new ListItemView();
//获取list_item布局文件的视图
convertView = (View)m_listContainer.inflate(R.layout.listview_style,null);
listItemView.tv = (TextView) convertView.findViewById(R.id.textview);
convertView.setTag(listItemView); }else {
listItemView = (ListItemView)convertView.getTag();
}
Map<String, String> map = m_MapItems.get(position);
return convertView;
} }

Listview模板的更多相关文章

  1. Android --ListView模板

    调整了近一上午的模板 ListView表头 <?xml version="1.0" encoding="utf-8"?> <LinearLay ...

  2. wpf 中 theme 的使用 和 listview 模板的使用.

    theme 文件 <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentatio ...

  3. .NET4.0的listview与DataPager的结合使用时的模板编辑

    1.设置listview模板样式: <asp:ListView ID="ListView1" runat="server" DataSourceID=&q ...

  4. ListView中动态显示和隐藏Header&Footer

    ListView的模板写法 ListView模板写法的完整代码: android代码优化----ListView中自定义adapter的封装(ListView的模板写法) 以后每写一个ListView ...

  5. ListView Web 服务器控件概述(MSDN)

    1: "折叠"图像"展开"图像"复制"图像"复制悬停"图像 全部折叠全部展开 代码:全部 代码:多个 代码:Visual ...

  6. Smobiler控件的使用:ListView的数据绑定及实现多选

    环境 SmobilerDesigner 4.7 Visual Studio 2010以上 正文 listview绑定数据 打开Visual Studio ,新建一个SmobilerApplicatio ...

  7. listview界面显示

    1.布局写listview      2.找到listview           3.封装新闻数据到list集合中 ,目的是为adapter提供数据展示.     4.封装一个Adapter类继承B ...

  8. ASP.NET数据绑定控件简介

    •数据绑定分为数据源和数据绑定控件两部分(①数据绑定控件通过数据源获取和修改数据②数据绑定控件通过数据源隔离数据提供者和数据使用者)数据绑定控件→数据源→数据库•数据源:SqlDataSource(连 ...

  9. Android学习笔记-Adapter基础讲解

    本节引言 从本节开始我们要讲的UI控件都是跟Adapter(适配器)打交道的,了解并学会使用这个Adapter很重要, Adapter是用来帮助填充数据的中间桥梁,简单点说就是:将各种数据以合适的形式 ...

随机推荐

  1. HDU 1234 简单模拟题

    题目很简单不多说了,我只是觉得这题目的输入方式还是很有特点的 #include <cstdio> #include <cstring> #include <algorit ...

  2. noip模拟赛 轰炸

    题目描述 C国和W国爆发了战争!YJC决定对W国的n个城市进行轰炸.每个城市都有一个重要度ai.设xi=‘重要度大于ai的城市数+1’,那么编号为i城市就是第xi个被轰炸的城市.显然这样能保证重要度大 ...

  3. 1010 过河卒 2002年NOIP全国联赛普及组codevs

    1010 过河卒  2002年NOIP全国联赛普及组codevs 题目描述 Description 如图,A 点有一个过河卒,需要走到目标 B 点.卒行走规则:可以向下.或者向右.同时在棋盘上的任一点 ...

  4. 关于System.Convert那些事

    关于System.Convert那些事 前言 不知咋的,今天腰疼的不行,疼的站不起来了,今下午突然就疼起来了,唉,这是身体要垮了的节奏啊,再加上自己的VAX试用期到了,弄了半天也不行,烦. 正文 看到 ...

  5. 自由宣言--《I Have a Dream》(马丁.路德.金)

    I Have a Dream by Martin Luther King, Jr. I am happy to join with you today in what will go down in ...

  6. Tomcat手工搭建Jsp和Servlet程序

    要执行J2EE的程序,就必须安装相关的容器.而怎样选择JSP+Servlet模式.Tomcat是非常重要的选择之中的一个,是世界上最为广泛的Servlet和JSP容器. 下载: 1. URL: htt ...

  7. jsp,velocity,freemark页面引擎的比較

    在java领域.表现层技术主要有三种:jsp.freemarker.velocity. jsp是大家最熟悉的技术 长处: 1.功能强大,能够写java代码 2.支持jsp标签(jsp tag) 3.支 ...

  8. Ubuntu14 中安装 VMware10 Tools工具&lt;2&gt;

    网上说已经针对上一篇提到的无法显示共享文件夹的问题做了补丁.补丁地址是https://github.com/rasa/vmware-tools-patches,我没有成功,还是出现"hgfs ...

  9. tomcat连接mysql的3个问题解决

    转载请标明出处: 本文出自:[ouyida3的博客] 1.BasicDataSourceFactory Caused by: java.lang.ClassNotFoundException: org ...

  10. 1159--Palindrome(dp:回文串变形2)

    Palindrome Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 53431   Accepted: 18454 Desc ...