日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2023/12/10 编程问答 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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");

調用起來倒也方便的

具體調用,遍歷代碼

@Overridepublic 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;}

  

?

轉載于:https://www.cnblogs.com/userbibi/archive/2012/03/29/2423202.html

總結

以上是生活随笔為你收集整理的intent几种传值数组、对象、集合(Array,Object,List)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。