一万年来谁著史,三千里外欲封侯。这篇文章主要讲述08_Android中的SimpleAdapter的使用相关的知识,希望能为你提供帮助。
??1 目的界面
文章图片
2、编写android清单文件
<
?xml version="1.0"encoding="utf-8"?>
< manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.itheima28.simpleadapterdemo" android:versionCode="1" android:versionName="1.0"> < uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19"/> < application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme"> < activity android:name="com.itheima28.simpleadapterdemo.MainActivity" android:label="@string/app_name"> < intent-filter> < action android:name="android.intent.action.MAIN" /> < category android:name="android.intent.category.LAUNCHER"/> < /intent-filter> < /activity> < /application> < /manifest> |
<
RelativeLayout 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" tools:context=".MainActivity"> < ListView android:id="@+id/listview" android:layout_width="match_parent" android:layout_height="match_parent"/> < /RelativeLayout> |
<
?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="wrap_content" android:gravity="center_vertical" android:orientation="horizontal" android:padding="10dip"> < ImageView android:id="@+id/iv_icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src=https://www.songbingjia.com/android/"@drawable/f007"/> < TextView android:id="@+id/tv_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dip" android:text="张三" android:textColor="#FF0000" android:textSize="23sp"/> < /LinearLayout> |
package com.itheima28.simpleadapterdemo;
import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.widget.ListView; import android.widget.SimpleAdapter; public class MainActivity extends ActionBarActivity { @Override protected void onCreate(BundlesavedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ListView mListView = (ListView)findViewById(R.id.listview); List< Map< String, Object> > data = https://www.songbingjia.com/android/new ArrayList< Map< String,Object> > (); Map< String, Object> map = newHashMap< String,Object> (); map.put("name", "张三1"); map.put("icon", R.drawable.f007); data.add(map); map = new HashMap< String,Object> (); map.put("name", "张三2"); map.put("icon", R.drawable.f007); data.add(map); map = new HashMap< String,Object> (); map.put("name", "张三3"); map.put("icon", R.drawable.f007); data.add(map); map = new HashMap< String,Object> (); map.put("name", "张三4"); map.put("icon", R.drawable.f007); data.add(map); map = new HashMap< String,Object> (); map.put("name", "张三5"); map.put("icon", R.drawable.f007); data.add(map); SimpleAdapter adapter = new SimpleAdapter( this, //上下文 data, //listView绑定的数据 R.layout.listview_item, //listview的子条目的布局的id new String[]{"name","icon"}, //data数据中的map集合里的key new int[]{R.id.tv_name,R.id.iv_icon}); //resource中的id mListView.setAdapter(adapter); } } |
【08_Android中的SimpleAdapter的使用】
推荐阅读
- Android系统优化
- Android进程间通信之内部类作为事件监听器
- android自己定义TextView
- 百度地图SDK调试SDKInitializer.initialize(getApplicationContext())错误
- Android调试的Log.d()没有输出
- Android的cookie的接收和发送
- Android中关于JNI 的学习在JNI层訪问Java端对象
- android AIDL 实践之传递简单字串
- Android UI开发第四十三篇——使用Property Animation实现墨迹天气3.0引导界面及动画实现