刚学 listview ,参考网上的教程

http://www.cnblogs.com/allin/archive/2010/05/11/1732200.html

自己实现了一个 listview ,使用的是 SimpleAdapter ,稍微有点改动

代码如下:

public classSListViewActivity extendsActivity{
/** Calledwhentheactivityisfirstcreated. */
privateListViewiLv;
@Override
public voidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
iLv=(ListView) this.findViewById(R.id.lv);
SimpleAdapterada= newSimpleAdapter( this,getData(),R.layout.vlist, newString[]{"title","info","img"},
new int[]{R.id.title,R.id.info,R.id.img});
iLv.setAdapter(ada);

}
privateList<Map<String,Object>>getData()
{
List<Map<String,Object>>list= newArrayList<Map<String,Object>>();
Map<String,Object>map= newHashMap<String,Object>();
map.put("title","G1");
map.put("info","google");
map.put("img",R.drawable.i1);
list.add(map);

map= newHashMap<String,Object>();
map.put("title","G2");
map.put("info","google2");
map.put("img",R.drawable.i1);
list.add(map);

returnlist;
}

------

xml 代码

main.xml

<? xmlversion="1.0"encoding="utf-8" ?>
< LinearLayout xmlns:android ="http://schemas.android.com/apk/res/android"
android:layout_width
="fill_parent"
android:layout_height
="fill_parent"
android:orientation
="vertical" >

< ListView
android:id ="@+id/lv"
android:layout_width
="fill_parent"
android:layout_height
="fill_parent"
/>

</ LinearLayout >

vlist.xml 这个是自定义 listview 的布局文件

<? xmlversion="1.0"encoding="utf-8" ?>
< LinearLayout xmlns:android ="http://schemas.android.com/apk/res/android"
android:layout_width
="fill_parent"
android:layout_height
="fill_parent" >

< ImageView
android:id ="@+id/img"
android:layout_width
="wrap_content"
android:layout_height
="wrap_content"
android:layout_margin
="3px"
/>
< LinearLayout
android:layout_width ="wrap_content"
android:layout_height
="wrap_content"
android:orientation
="vertical"
>
< TextView
android:id ="@+id/title"
android:layout_width
="wrap_content"
android:layout_height
="wrap_content"
android:textColor
="#ffffff"
android:textSize
="22px"
/>
< TextView
android:id ="@+id/info"
android:layout_width
="wrap_content"
android:layout_height
="wrap_content"
android:textColor
="#ffffff"
android:textSize
="12px"
/>
</ LinearLayout >
</ LinearLayout >

在刚做出来后,一直没有办法运行,最终发现 TextView 这里写错了,改正确后就可以运行了。

更多相关文章

  1. Android(安卓)滑动返回Activity的实现代码
  2. 最简单的BufferQueue测试程序(一)
  3. RecyclerView的使用详解
  4. Android之RecyclerView实现时光轴
  5. android ConstraintLayout百分比适配
  6. Android(安卓)使用JAVA代码控制UI界面
  7. Android(安卓)工程目录简单结构
  8. Android文章目录
  9. android中图片加载到内存的实例代码

随机推荐

  1. Android:Galaxy Nexus升级到4.1.2,并root(设
  2. This Android SDK requires Android Deve
  3. Android(1)进程通信基础知识
  4. Android学习之线性布局管理器
  5. Unity与Android通信
  6. Adapter那点事
  7. 要学习android了
  8. android 获取图片
  9. android灵活布局
  10. Android IPC 通讯机制源码分析 二