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: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=".MainDemo" > <TextView
android:id="@+id/info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="" /> <ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView> </LinearLayout>

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="horizontal"
tools:context=".MainActivity"
android:id="@+id/datalist"> <ImageView
android:id="@+id/pic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:src="@drawable/ic_launcher"/> <LinearLayout android:layout_width="180px"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context=".MainActivity"
android:gravity="left"> <TextView
android:id="@+id/company"
android:textSize="16px"
android:padding="3px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/> <TextView
android:id="@+id/ceo"
android:padding="3px"
android:textSize="10px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout android:layout_width="200px"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context=".MainActivity"
android:gravity="left"> <TextView
android:id="@+id/type"
android:textSize="16px"
android:padding="1px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/> <ImageView
android:id="@+id/score"
android:padding="1px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/> </LinearLayout>
</LinearLayout>

java

package app.android.MainDemo;

import android.os.Bundle;

import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast; public class MainDemo extends Activity { private int pic[]=new int[]
{
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
}; private String data[][]=new String[][]
{
{"百度","李彦宏","搜索",R.drawable.ic_launcher+""},
{"阿里巴巴","马云","电子商务",R.drawable.ic_launcher+""},
{"腾讯","马化腾","社交网络",R.drawable.ic_launcher+""},
{"新浪","曹国伟","社交媒体",R.drawable.ic_launcher+""},
{"腾讯","马化腾","社交网络",R.drawable.ic_launcher+""},
{"新浪","曹国伟","社交媒体",R.drawable.ic_launcher+""},
}; private ListView dataList=null;
private List<Map<String,String>> list=new ArrayList<Map<String,String>>();
private SimpleAdapter simpleAdapter=null;
private TextView info=null; @Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_demo); this.dataList=(ListView) super.findViewById(R.id.datalist); this.info=(TextView)super.findViewById(R.id.info); //
// //将我们每一条记录添加到我们的Map当中
for(int i=0;i<data.length;i++){
//定义我们的Map数据
Map<String,String> map=new HashMap<String, String>();
//添加数据 map.put("pic", String.valueOf(pic[i]));
map.put("company",data[i][0]);
map.put("ceo", data[i][1]);
map.put("type", data[i][2]);
map.put("score", data[i][3]);
this.list.add(map);
} this.simpleAdapter=new SimpleAdapter
(
this,
this.list,
R.layout.maindemo_datalist,
new String[]{"pic","company","ceo","type","score"},
new int[]{R.id.pic,R.id.company,R.id.ceo,R.id.type,R.id.score}
);
this.dataList.setAdapter(simpleAdapter);
this.dataList.setOnItemClickListener(new OnItemClickListener()
{ @Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { @SuppressWarnings("unchecked")
Map<String,String> map=(Map<String, String>)
MainDemo.this.simpleAdapter.getItem(arg2); Toast.makeText(MainDemo.this, "onItemClick=>:"+arg2, 3000).show(); String company=map.get("company");
String ceo=map.get("ceo");
String type=map.get("type");
MainDemo.this.info.setText("您选择的公司是:=>"+company+"ceo为"+ceo+"type:"+type); }
}); } }

效果:

android listview simpleAdaper的更多相关文章

  1. android ListView 九大重要属性详细分析、

    android ListView 九大重要属性详细分析. 1.android ListView 一些重要属性详解,兄弟朋友可以参考一下. 首先是stackFromBottom属性,这只该属性之后你做好 ...

  2. Android ListView onItemClick Not Work

    Android ListView onItemClick Not Work ListView item中有Button和RadioButton的时候,它的Item点击事件不起作用,需要设置item的属 ...

  3. 【腾讯Bugly干货分享】Android ListView与RecyclerView对比浅析--缓存机制

    本文来自于腾讯bugly开发者社区,非经作者同意,请勿转载,原文地址:http://dev.qq.com/topic/5811d3e3ab10c62013697408 作者:黄宁源 一,背景 Recy ...

  4. Android ListView 常用技巧

    Android ListView 常用技巧 Android TextView 常用技巧 1.使用ViewHolder提高效率 ViewHolder模式充分利用了ListView的视图缓存机制,避免了每 ...

  5. Android listview addHeaderView 和 addFooterView 详解

    addHeaderView()方法:主要是向listView的头部添加布局addFooterView()方法:主要是向listView的底部添加布局 需要注意的是添加布局的时候应该添加从父容器开始添加 ...

  6. Android ListView滑动过程中图片显示重复错乱闪烁问题解决

    最新内容建议直接访问原文:Android ListView滑动过程中图片显示重复错乱闪烁问题解决 主要分析Android ListView滚动过程中图片显示重复.错乱.闪烁的原因及解决方法,顺带提及L ...

  7. Android --ListView分页

    参考博客:Android ListView分页加载(服务端+android端)Demo 监听OnScrollListener事件 class OnListScrollListener implemen ...

  8. Android ListView ListActivity PreferenceActivity背景变黑的问题ZT

    Android ListView ListActivity PreferenceActivity背景变黑的问题 ListView在滚动时背景会变暗甚至变黑,这个要从Listview的效果说起,默认的L ...

  9. android listview去掉分割线

    1:android listview去掉分割线 1>设置android:divider="@null" 2>android:divider="#0000000 ...

随机推荐

  1. Inventory Costing in AX 2009

    I wanted to explore some scenarios that illustrate a few important concepts related to inventory cos ...

  2. 两个有意思的模式在ECMAScript中的实现

    简介 本篇文章对设计模式进行了筛选, 只列举两个有意思(坑)的设计实现, 如有错误愿闻其详. 构造函数 ECMAScript中的构造函数和其他语言的有那么点特别之处,可以认为, 一个函数, 如果被以n ...

  3. CentOS6.6安装vmware workstation报错

    本人系统用的是centos6.6,安装了vmware workstation,启动后一直如下图报错,相关内核已经安装了的,哪位前辈如果解决过这样的问题,麻烦指点指点,小弟在此先谢过了.

  4. Win7+Docker(boo2docker)搭建php开发环境简略

    之所以称谓简略 是不准备配图的意思 嘿嘿! 步骤1: 到docker官网下载Docker Toolbox,并完全安装 步骤2: 安装完成后,运行在桌面新生成的快捷方式:Docker Quickstar ...

  5. windows下搭建nginx+php+mysql环境

    一.下载需要的东西 1.nginx:http://nginx.org/en/download.html 2.php:http://php.net/downloads.php 3.mysql:(暂时先不 ...

  6. VR原理讲解及开发入门

    本文是作者obuil根据多年心得专门为想要入门的VR开发者所写,由52VR网站提供支持.   1. VR沉浸感和交互作用产生的原理:   在之前,我们观看一个虚拟的创造内容是通过平面显示器的,52VR ...

  7. linux--------------今天又遇到一个奇葩的问题,就是linux文件的权限已经是777了但是还是没有写入权限,按照下面的命令就解决了

    查看SELinux状态: 1./usr/sbin/sestatus -v      ##如果SELinux status参数为enabled即为开启状态 SELinux status:         ...

  8. XPath 运算符

    XPath 表达式可返回节点集.字符串.逻辑值以及数字. XPath 运算符 下面列出了可用在 XPath 表达式中的运算符: 运算符 描述 实例 返回值 | 计算两个节点集 //book | //c ...

  9. 安装hive+mysql

    1.源码安装mysql 以root用户首先安装libaio-0.3.104.tar.gz tar zxvf libaio-0.3.104.tar.gz cd libaio-0.3.104 make p ...

  10. java布局学习 (三)

    前文已经讲了常用的4个布局了,今天再介绍最后的三个布局: 5.CardLayout 6.BoxLayout 7.空白布局null (五)CardLayout   纸牌布局 首先这种布局不是二维布局,而 ...