日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

08_Android中的SimpleAdapter的使用

發布時間:2024/9/27 Android 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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>

3 activity_main.xml的文件內容

<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>

4 listview_item.xml的文件內容

<?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="@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>

5 MainActivity的內容如下:

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(Bundle savedInstanceState) {

?????? super.onCreate(savedInstanceState);

?????? setContentView(R.layout.activity_main);

??????

?????? ListView mListView = (ListView) findViewById(R.id.listview);

??????

?????? List<Map<String, Object>> data = new ArrayList<Map<String,Object>>();

??????

?????? Map<String, Object> map = new HashMap<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的使用的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。