码迷,mamicode.com
首页 > 其他好文 > 详细

Demo12SimpleAdapter

时间:2016-03-09 22:28:07      阅读:275      评论:0      收藏:0      [点我收藏+]

标签:

/Users/alamps/AndroidStudioProjects/Demo12SimpleAdapter/Demo12SimpleAdapter/src/main/res/layout/data_list.xml

    <TableLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="42dp">
        <TableRow>
            <ImageView
                    android:id="@+id/_icon"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/icon"/>
            <TextView
                    android:id="@+id/_id"
                    android:textSize="15px"
                    android:gravity="center_vertical"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                     />

            <TextView
                    android:id="@+id/_name"
                    android:textSize="15px"
                    android:gravity="center_vertical"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                   />
        </TableRow>
    </TableLayout>


==========================
/Users/alamps/AndroidStudioProjects/Demo12SimpleAdapter/Demo12SimpleAdapter/src/main/res/layout/activity_main.xml

<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:orientation="vertical"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".MainActivity">

    <TextView
        android:textSize="25px"
        android:gravity="center_vertical"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="信息列表INFOLIST" />
    <ListView
        android:id="@+id/data_list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        />

</LinearLayout>
==============================
package com.example.demo12simpleadapter;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MainActivity extends Activity {

    private String data[][]={{"01","www.csdn.com"},{"02","www.baidu.com"},{"03","wwww.alamps.com"},{"04","www.iteye.com"},{"05","www.google.com"},{"06","www.qq.com"}};
    private List<Map<String,String>>  list = new ArrayList<Map<String,String>>();
    private ListView listView;
    private SimpleAdapter simpleAdapter=null;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        this.listView= (ListView) super.findViewById(R.id.data_list);//mac android studio [alt+return] == eclipse[ctrl+1]

        for (int i =0;i<this.data.length;i++){

            Map<String,String> map = new HashMap<String, String>();
            map.put("_id",data[i][0]);
            map.put("_name",data[i][1]);
            this.list.add(map);
        }
        //public SimpleAdapter(android.content.Context context, java.util.List<? extends java.util.Map<java.lang.String,?>> data, int resource, java.lang.String[] from, int[] to) { /* compiled code */ }
        this.simpleAdapter = new SimpleAdapter(this,
                this.list//数据
                ,R.layout.data_list,//显示格式
                new String[]{"_id","_name"},new int[]{R.id._id,R.id._name});
       this.listView.setAdapter(this.simpleAdapter);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    
}


技术分享

 

Demo12SimpleAdapter

标签:

原文地址:http://www.cnblogs.com/alamps/p/5259925.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!