【Android】14、SimpleAdapter
来源:互联网 发布:转行it 知乎 编辑:程序博客网 时间:2024/06/05 09:22
1、使用SimpleAdapter实现图文混编
在布局文件中编写代码
——添加ListView标签(main.xml)
——编写行布局文件(item.xml)
2、在Activity中编写代码
——获取ListView对象
——准备数据源(List<Map>)
——配置适配器(SimpleAdapter)
——将适配器关联到ListView
3、实例。
————————item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants">
<ImageView
android:id="@+id/logo"
android:src="@mipmap/qq"
android:padding="5dp"
android:layout_width="100dp"
android:layout_height="80dp"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
/>
<Button
android:id="@+id/button"
android:text="卸载"
android:textColor="#FFF"
android:background="@mipmap/btn"
android:layout_width="70dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_marginRight="20dp"/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/logo"
android:layout_toLeftOf="@id/button">
<TextView
android:id="@+id/title"
android:text="QQ"
android:textSize="20sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"/>
<TextView
android:id="@+id/version"
android:text="版本:1.0"
android:textColor="#aaa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/title"/>
<TextView
android:id="@+id/size"
android:text="空间:12M"
android:textColor="#aaa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/version"/>
</RelativeLayout>
</RelativeLayout>
———————————main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:id="@+id/lv_soft"
android:layout_width="match_parent"
android:layout_height="match_parent"></ListView>
</RelativeLayout>
————————————MainActivity.java
//1,获取ListView对象
ListView lv_soft= (ListView) findViewById(R.id.lv_soft);
//2,数据源
List<Map<String,Object>> list=new ArrayList<Map<String,Object>>();
Map<String,Object> map =new HashMap<String,Object>();
map.put("logo",R.mipmap.qq);
map.put("title","QQ");
map.put("version","版本:1.0");
map.put("size","空间:32M");
list.add(map);
map=new HashMap<String,Object>();
map.put("logo",R.mipmap.weixin);
map.put("title","微信");
map.put("version","版本:2.2");
map.put("size","空间:12M");
list.add(map);
map =new HashMap<String,Object>();
map.put("logo",R.mipmap.qzone);
map.put("title","QQ空间");
map.put("version","版本:4.3");
map.put("size","空间:18M");
list.add(map);
//3,适配器
SimpleAdapter adapter = new SimpleAdapter(
this,
list,
R.layout.item,
new String[]{"logo","title","version","size"},
new int[]{R.id.logo,R.id.title,R.id.version,R.id.size}
);
//4,关联ListView
lv_soft.setAdapter(adapter);
4、ListView行布局SimpleAdapter无法获得焦点解决办法。
因为Button按钮有“抢”焦点的行为,在行布局的最外层容器加下列代码即可
android:descendantFocusability="blocksDescendants"
这样可使得按到行布局的时候,有颜色改变。
- 【Android】14、SimpleAdapter
- android SimpleAdapter
- Android SimpleAdapter
- Android SimpleAdapter
- Android SimpleAdapter
- Android SimpleAdapter
- Android的SimpleAdapter
- Android SimpleAdapter ViewBinder 示例
- android 适配器 simpleAdapter
- Android SimpleAdapter的参数
- Android中的SimpleAdapter
- Android适配器之-----SimpleAdapter
- android之SimpleAdapter
- Android中的类SimpleAdapter
- Android SimpleAdapter源码详解
- Android SimpleAdapter显示问题
- android:listview SimpleAdapter
- Android--ListView和SimpleAdapter
- NameNode格式化失败问题的解决
- 常用游戏逻辑编程
- 验证二叉树后序遍历序列是否符合要求
- “无中生有”计算机视觉探奇
- 我对C++ string和length方法的一个长期误解------从protobuf序列化说起(没处理好会引起数据丢失、反序列化失败哦!)
- 【Android】14、SimpleAdapter
- **1051 - My-graph-同构图
- javaPOI导出excel代码
- Collection和Map
- 初学JAVA易错点1
- ViewPager+Fragment取消预加载(延迟加载)
- Spring之DataSource配置
- HDU 5952 - Counting Cliques
- 欢迎使用CSDN-markdown编辑器