ListView布局 采用SimpleAdapter
来源:互联网 发布:电商源码 编辑:程序博客网 时间:2024/06/15 07:38
public class ListView1Activity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_list_view1);overridePendingTransition(android.R.anim.slide_in_left,android.R.anim.slide_out_right);ListView listview2=(ListView) findViewById(R.id.listview2);SimpleAdapter simpleadapt=new SimpleAdapter(this, getFriendData(),R.layout.listview,new String[]{"name","age","addr","pic"}, new int[]{R.id.name,R.id.age,R.id.addr,R.id.pic}); listview2.setOnItemSelectedListener(new OnItemSelectedListener() {@Overridepublic void onItemSelected(AdapterView<?> parent, View view,int position, long id) {Toast.makeText(getApplicationContext(), "你选了"+parent.getItemIdAtPosition(position)+"美女", 200).show();}@Overridepublic void onNothingSelected(AdapterView<?> parent) {} }); listview2.setAdapter(simpleadapt);}//获得数据private List<Map<String,Object>> getFriendData(){List<Map<String,Object>> list=new ArrayList<Map<String,Object>>();List<Friend> friendlist=new ArrayList<Friend>();friendlist.add(new Friend("晓雪","安徽",17,R.drawable.b));friendlist.add(new Friend("小艳","辽宁",19,R.drawable.c));friendlist.add(new Friend("君婕","安徽",17,R.drawable.d));friendlist.add(new Friend("邓攀","珠海",20,R.drawable.girl));friendlist.add(new Friend("小高","珠海",20,R.drawable.c));Map<String,Object> map=null;for (int i = 0; i < friendlist.size(); i++) { map=new HashMap<String,Object>();map.put("name",friendlist.get(i).getName());map.put("addr",friendlist.get(i).getAddr());map.put("age", friendlist.get(i).getAge());map.put("pic", friendlist.get(i).getPic());list.add(map);} return list;}}
布局文件如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".ListView1Activity" android:orientation="vertical" > <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="listview之SimpleAdapt复杂练习" /> <ListView android:layout_height="wrap_content" android:layout_width="match_parent" android:choiceMode="singleChoice" android:id="@+id/listview2" ></ListView> </LinearLayout>
自定义的布局文件如下:
<?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:id="@+id/pic" android:layout_width="65dp" android:layout_height="60dp" /> <LinearLayout android:layout_height="wrap_content" android:layout_width="match_parent" android:orientation="vertical" > <TextView android:id="@+id/name" android:layout_height="wrap_content" android:layout_width="wrap_content"/> <TextView android:id="@+id/age" android:layout_height="wrap_content" android:layout_width="wrap_content"/> <TextView android:id="@+id/addr" android:layout_height="wrap_content" android:layout_width="wrap_content"/> </LinearLayout> </LinearLayout>
0 0
- ListView布局 采用SimpleAdapter
- Android学习笔记之ListView采用SimpleAdapter
- 采用ListView实现数据列表显示——SimpleAdapter
- ListView(SimpleAdapter)
- ListView SimpleAdapter
- listview simpleadapter
- ListView SimpleAdapter
- ListView--SimpleAdapter
- android listView 更改simpleAdapter中布局layout中textView颜色
- android--(布局ListView、优化、刷新分页、ArrayAdapter、SimpleAdapter 、BaseAdapter)
- 26、使用SimpleAdapter创建ListView和自定义Toast布局显示
- 采用祯布局做双重listview
- GridView 加载数据 采用SimpleAdapter.
- 用SimpleAdapter实现ListView
- ListView之SimpleAdapter
- SimpleAdapter与ListView
- 美化ListView(SimpleAdapter)
- ListView With SimpleAdapter
- Android-SurfaceView与SurfaceHolder对象
- Mybatis添加Ehcache支持
- MinGW的问题与使用
- driver verifier查找隐藏的内存泄露BUG
- soa部署项目,启动时报错:No credential mapper entry found for password indirection user
- ListView布局 采用SimpleAdapter
- 寄宿WCF服务
- 字符驱动程序设计学习笔记4-2
- Python 3.3 (2)
- java中的volatile和transient关键字
- Windows下Qt 5.2 for Android开发入门
- 苹果iMessage垃圾信息泛滥:运营商难涉及
- 背包问题的几种解法及变形
- ORACLE分区表、分区索引(转)