zoukankan      html  css  js  c++  java
  • android中ListView控件&&onItemClick事件中获取listView传递的数据

     

    http://blog.csdn.net/aben_2005/article/details/6592205

    本文转载自:android中ListView控件&&onItemClick点击事件

    1. listView= (ListView) this.findViewById(R.id.listview);  
    2.         List<HashMap<String,String>>data = new ArrayList<HashMap<String,String>>();  
    3.         UserService us = new UserService(this);  
    4.         List<User> users = us.getScrollDate(0, 10);  
    5.         for(User u : users){  
    6.          HashMap<String,String> map = new HashMap<String, String>();  
    7.          map.put("userid", String.valueOf(u.getUserid()));  
    8.          map.put("name", u.getName());  
    9.          map.put("age", String.valueOf(u.getAge()));  
    10.          data.add(map);  
    11.         }  
    12.         SimpleAdapter adapter = new SimpleAdapter(this,data,R.layout.useritem,new String[]{"userid","name","age"},new int[]{R.id.userid,R.id.name,R.id.age});  
    13.           
    14.        listView.setAdapter(adapter);  
    15.         listView.setOnItemClickListener(new OnItemClickListener(){  
    16.   
    17.    @SuppressWarnings("unchecked")  
    18.    @Override  
    19.    public void onItemClick(AdapterView<?> parent, View view,  
    20.      int position, long id) {  
    21.     ListView listView = (ListView)parent;  
    22.     HashMap<String, String> map = (HashMap<String, String>) listView.getItemAtPosition(position);  
    23.     String userid = map.get("userid");  
    24.     String name = map.get("name");  
    25.     String age = map.get("age");  
    26.     Toast.makeText(SQLiteCRUDActivity.this, userid +" , "+ name +" , "+ age ,Toast.LENGTH_LONG).show();  
    27.    }  
    28.         }); 
  • 相关阅读:
    spring cloud config 属性加解密
    IntelliJ IDEA 快捷键
    SQL Server 2012 安装图解教程(附sql2012下载地址)
    spring cloud 启动报错-must be declared as an @AliasFor [serviceId], not [name].
    MySQL主从复制配置
    恢复MySQL数据库删除的数据
    java.lang.IllegalStateException: No instances available for localhost
    蜘蛛牌 (DFS)
    加油站问题 (优先队列)
    堆的操作的复杂度
  • 原文地址:https://www.cnblogs.com/antis/p/5510174.html
Copyright © 2011-2022 走看看