• Android中ListView控件onItemClick事件中获取listView传递的数据


    声明:本文转载自:http://blog.csdn.net/aben_2005/article/details/6592205

    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.        listView.setAdapter(adapter);  
    14.         listView.setOnItemClickListener(new OnItemClickListener(){  
    15. @SuppressWarnings("unchecked")  
    16. @Override  
    17. public void onItemClick(AdapterView<?> parent, View view,  
    18. int position, long id) {  
    19.     ListView listView = (ListView)parent;  
    20.     HashMap<String, String> map = (HashMap<String, String>) listView.getItemAtPosition(position);  
    21.     String userid = map.get("userid");  
    22.     String name = map.get("name");  
    23.     String age = map.get("age");  
    24.     Toast.makeText(SQLiteCRUDActivity.this, userid +" , "+ name +" , "+ age ,Toast.LENGTH_LONG).show();  
    25.    }  
    26.         }); 
  • 相关阅读:
    "Principles of Reactive Programming" 之<Actors are Distributed> (3)
    Clojure语法学习-循环
    建立Clojure开发环境-使用IDEA和Leiningen
    速查笔记(Linux Shell编程<上>)
    Exception thrown in catch and finally clause
    linux fork的缺点
    redhat6.4 install 163 source
    linux /etc/hosts 配置问题
    linux sed
    STL 源码分析 (SGI版本, 侯捷著)
  • 原文地址:https://www.cnblogs.com/JasonTech0713/p/5510196.html
Copyright © 2020-2023  润新知