intent几种传值数组、对象、集合(Array,Object,List)

1.Array

 

?
private ArrayList<String> checkList= new ArrayList<String>();
  Intent intent= new  Intent(mytext. this ,show. class );
  intent.putStringArrayListExtra( "list" , checkList);
  startActivity(intent);

 调用

?
Intent intent= this .getIntent();
ArrayList<String> list=intent.getStringArrayListExtra( "list" );
ArrayList<HashMap<String,String>> mylist= new ArrayList<HashMap< String,String>>();
///listview使用
ListView listview=(ListView)findViewById(R.id.MyListView);
for ( int i= 0 ;i<list.size();i++)
{
  HashMap<String,String> map= new HashMap<String,String>();
  map.put( "ItemTitle" , list.get(i).toString());
  mylist.add(map);
}
SimpleAdapter mSchedule= new SimpleAdapter( this ,mylist,R.layout.show, new String[]{ "ItemTitle" , "ItemTitle" }, new int []{R.id.ItemTitle,R.id.ItemTitle});
listview.setAdapter(mSchedule);

  

2.对象、列表(object,List)

前面都一样,上遍文章已经讲解,这边补充一下,只讲一个Serializable的。。另一个Parcelable都差不多,各自实现各自的接口,调用的时候可以不用那么麻烦,真心不喜欢用Bundle ,挺多此一举的

改写

如果是List

  List<Parking_Info> list=new  ArrayList<Parking_Info>();//搜索结果集合

?
Intent  intent= new Intent(LinkMap. this ,MapList. class );
              intent.putExtra( "list" , (Serializable)list);
startActivity(intent);

这边直接强制转化就行了,再接受的时候用(List<Parking_Info>) getIntent().getSerializable("list")就可以接受到List<Parking_Info>数据了

Listlist=(List)getIntent().getSerializableExtra("list");

调用起来倒也方便的

具体调用,遍历代码

?
@Override
public void onCreate(Bundle savedInstanceState) {
  
     super .onCreate(savedInstanceState);
     setContentView(R.layout.listmain);
    
  //   List<Parking_Info> list=(List<Parking_Info>)getIntent().getSerializableExtra("list");
     //创建适配器
     SimpleAdapter adapter = new SimpleAdapter( this ,getData(),R.layout.maplist,
             new String[]{ "name" , "kongwei" , "code" , "addr" },
             new int []{R.id.name,R.id.kongwei,R.id.code,R.id.addr});
    
     setListAdapter(adapter);
  // ListView listview=(ListView)findViewById(R.id.SearchList);
//   listview.setAdapter(adapter);
    
     };
    
    
      private List<Map<String, Object>> getData() {      
          List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();      
        
          //获取参数
         List<Parking_Info> mylist=(List<Parking_Info>)getIntent().getSerializableExtra( "list" );
       
         for ( int i= 0 ;i<mylist.size();i++)
         {
              Map<String, Object> map = new HashMap<String, Object>();
             map.put( "name" ,mylist.get(i).getPrk_name());
             map.put( "kongwei" , "空位:" +mylist.get(i).getKongwei());
             map.put( "code" , "收费:" + mylist.get(i).getCode());
             map.put( "addr" , "地址:" +mylist.get(i).getPrk_addr());
              list.add(map);   
           //   Toast.makeText(this, mylist.get(5).getPrk_name(), Toast.LENGTH_LONG).show();
        
         }
        
          return list;
          }

  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值