0
我試圖將數據存儲到包中並開始一個新的活動。然後在新的活動中,我想要取消數據。爲鑄造部分的代碼是follwing:通過意向傳遞一個包
Intent i = new Intent(MainActivity.this, ShowProductActivity.class);
Bundle bundle = new Bundle();
// Getting adapter of the listview
SimpleAdapter adapter = (SimpleAdapter) mListView.getAdapter();
bundle.putSerializable("param1", ((HashMap<String, Object>) adapter.getItem(position)));
i.putExtras(bundle);
startActivity(i);
一般來說,數據包含到包是如下:
Bundle[{param1={position=0, image=2130837504, flag=/data/data/com.example.app/cache/wpta_0.jpeg, price=Brand : Dash Price : 27}}]
我怎樣才能檢索到上述數據爲第二活動?我正在使用下面的代碼塊,但我無法訪問屬性。
Bundle bundle = this.getIntent().getExtras();
HashMap<String, Object> param1 = (HashMap<String, Object>)bundle.getSerializable("param1");
你是什麼意思,你不能訪問屬性?當你嘗試索引HashMap中的數據時會發生什麼? –