this.listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int idx, long id) {
Map<String,String> mapItem = (Map<String,String>)MainActivity.this.simpleAdapter.getItem(idx);
String _id=mapItem.get("_id");
String _name=mapItem.get("_name");
MainActivity.this.info.setText("选择的数据ID:"+_id+"名称是:"+_name);
}
});
   <!--,显示选择的信息-->
<TextView
android:id="@+id/_info"
android:gravity="center_horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>

demo12

<!--<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">--> <!--<ListView&ndash;&gt;-->
<!--&lt;!&ndash;android:id="@+id/data_list"&ndash;&gt;-->
<!--&lt;!&ndash;android:layout_width="fill_parent"&ndash;&gt;-->
<!--&lt;!&ndash;android:layout_height="wrap_content"&ndash;&gt;-->
<!--&lt;!&ndash;/>--> <!--</LinearLayout>-->
<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"> <!--,显示选择的信息-->
<TextView
android:id="@+id/_info"
android:gravity="center_horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:textSize="25px"
android:gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="信息列表INFOLIST" /> <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>
package com.example.demo12simpleadapter;

import android.app.ListActivity;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map; public class MainActivity extends ListActivity {//Activity->ListActivity//改变1 private String data[][]={{"","www.csdn.com"},{"","www.baidu.com"},{"","wwww.alamps.com"},{"","www.iteye.com"},{"","www.google.com"},{"","www.qq.com"}};
private List<Map<String,String>> list = new ArrayList<Map<String,String>>();
private ListView listView;
private SimpleAdapter simpleAdapter=null;
//onItemClickListener
private TextView info=null; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);//改变5
//改变2
//this.listView= (ListView) super.findViewById(R.id.data_list);//mac android studio [alt+return] == eclipse[ctrl+1] this.info = (TextView) super.findViewById(R.id._info); for (int i =;i<this.data.length;i++){ Map<String,String> map = new HashMap<String, String>();
map.put("_id",data[i][]);
map.put("_name",data[i][]);
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.activity_main,//显示格式//改变5
new String[]{"_id","_name"},new int[]{R.id._id,R.id._name}); //改变3
// this.listView.setAdapter(this.simpleAdapter); this.listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int idx, long id) {
Map<String,String> mapItem = (Map<String,String>)MainActivity.this.simpleAdapter.getItem(idx);
String _id=mapItem.get("_id");
String _name=mapItem.get("_name");
MainActivity.this.info.setText("选择的数据ID:"+_id+"名称是:"+_name);
}
}); super.setListAdapter(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;
} }

Demo13的更多相关文章

  1. WPF Demo13 GridSplitter

    <Window x:Class="Commands.MainWindow" xmlns="http://schemas.microsoft.com/winfx/20 ...

  2. WPF Demo13通知项属性+数据绑定(代码层)

    <Window x:Class="BindingDemo1.MainWindow" xmlns="http://schemas.microsoft.com/winf ...

  3. Java基础学习(四)

    流程控制 /* 控制流程语句之---if 判断语句 格式一: 只适用于一种情况下去使用. if(判断条件){ 符合条件执行的代码; } 格式二:适用于两种情况下去使用 if(判断条件){ 符合条件执行 ...

  4. gulp + webpack + sass 学习

    笔记: new webpack.optimize.CommonsChunkPlugin 核心作用是抽离公共代码,chunks:['index.js','main.js'] 另一个作用就是单独生成一个j ...

  5. CSS3 text-shadow

    <!DOCTYPE html > <html > <head> <meta charset="utf-8"> <title&g ...

  6. Hibernate的抓取策略

    立即检索:当执行某行代码的时候,马上发出SQL语句进行查询(get())延迟检索:当执行某行代码的时候,不会马上发出SQL语句进行查询.当真正使用这个对象的时候才会发送SQL语句(load()) 类级 ...

  7. 来看看css3中的box-shadow

    不谈IE,只谈谈box-shadow的具体使用方法 语法: E {box-shadow: <length> <length> <length>?<length ...

  8. jQuery实践——选择器篇

      一.基本 #id: html:<div id="demo1">demo1</div> jQuery:$("#demo1").css( ...

  9. reactjs

    摘自阮一峰博客:http://www.ruanyifeng.com/blog/2015/03/react.html 现在最热门的前端框架,毫无疑问是 React . 上周,基于 React 的 Rea ...

随机推荐

  1. su terminal get around---docker root

    su : must be run from a terminal After some googling, I found the solution from Tero's glob. If you ...

  2. jQuery EasyUI---validatebox 校验规则扩展

    EasyUI 的 validatebox 插件, 验证规则相对比较单一也比较少,如下. rules: { email:{ validator: function(value){ return ...? ...

  3. 下载大图的demo by apple,值得研究和参考

    https://developer.apple.com/library/content/samplecode/LargeImageDownsizing/Introduction/Intro.html ...

  4. .Net程序员安卓学习之路2:访问网络API

    做应用型的APP肯定是要和网络交互的,那么本节就来实战一把Android访问网络API,还是使用上节的DEMO: 一.准备API: 一般都采用Json作为数据交换格式,目前各种语言均能输出Json串. ...

  5. 默认的app.js

    我们通过npm start 默认入口是app.js,如果想默认入口改为main.js,可以修改项目下的/bin/www文件把app修改main var app = require('../app');

  6. 解决Eclipse启动报错Failed to create the Java Virtual Machine

    电脑:2G内存,WIN7 32位. 启动adt-bundle-windows-x86-20140702\eclipse\eclipse.exe时,报错[Failed to create the Jav ...

  7. One Time Auth

    One Time Auth One-time authentication (shortened as OTA) is a new experimental feature designed to i ...

  8. c#网页爬虫初探

    一个简单的网页爬虫例子! html代码: <head runat="server"> <title>c#爬网</title> </head ...

  9. Sql server中内连接语句

    数据库中学生表和课程表如下: 内连接sql语句: select a.studentName,a.studentAge,b.courseName from student a inner join co ...

  10. c# key event

    使用C#写ui时,希望能够读取到键盘输入的事件,用于快捷键或者其他操作.本文记录操作创建key event的方法. 参考链接: http://csharp.net-informations.com/g ...