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. 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. });
上一篇:win7安装Python3.7时提示“Service Pack 1 is required to continue installation”


下一篇:20.(转)Android的样式(Style)和主题(Theme)