zoukankan      html  css  js  c++  java
  • Android 取得 ListView中每个Item项目的值

    首先我们须要创建 ListView 。这里假定我们已经创建好了而且使用SimpleAdapter设置好了adapter数据,看一下我们的adapter
    ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
    
    for (int i = 0; i < 10; i++) {
    HashMap<String, String> map = new HashMap<String, String>();
    map.put("shopName", "毛家饭店");
    map.put("shopAddr", "第" + i + "行内容");
    list.add(map);
    }
    
    adapter = new SimpleAdapter(this, list, R.layout.list_item_test,
    new String[] { "shopName", "shopAddr" }, new int[] {
    R.id.shopName, R.id.shopAddr });
    
    接下来我们操作 listview的单击事件
    listView.setOnItemClickListener(new OnItemClickListener() {
    
    @Override
    public void onItemClick(AdapterView<?> parent, View view,
    int position, long id) {
    // TODO Auto-generated method stub
    HashMap<String, String> map = (HashMap<String, String>) parent
    .getItemAtPosition(position);
    Toast.makeText(view.getContext(), map.get("shopName"),
    Toast.LENGTH_SHORT).show();
    }
    });
    
    这样我们就能得到商家的名称了,同一时候假设须要获取其他字段内容,仅仅要更改 map 的Key就能够了。
  • 相关阅读:
    delphi消息发送字符串
    Delphi2007 在Win10 下运行报错 Assertion failure
    python 定时器
    python 直接赋值 深浅拷贝
    python 闭包
    python 对象
    c++ sizeof和strlen
    c++入门笔记(一)
    python实现四种排序逻辑与代码
    webrtc autotest
  • 原文地址:https://www.cnblogs.com/yfceshi/p/7052433.html
Copyright © 2011-2022 走看看