Android Listview设置监听器并获取子项数据

废话不多说直接上图

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                
                Map <String,Object> map= new HashMap<String,Object>();
                **//重点!!!** 
              这里通过强转可以获得子项对象map,然后可以通过map的get获得子项的值
                HashMap<String,Object > map_item = (HashMap<String,Object >)listView.getItemAtPosition(position);
		
                Intent intent_delete = new Intent(MainActivity.this,delete_change.class);
                //获取map中的三项数据,并放入intent
                intent_delete.putExtra("id",map_item.get("id")+"");
                intent_delete.putExtra("name",map_item.get("name")+"");
                intent_delete.putExtra("banji",map_item.get("banji")+"");
                startActivity(intent_delete);
             //

            }
            
~~~

你可能感兴趣的:(Android)