1. Android中如何从一个Activity中ArrayList<HashMap<String,Object>>传递到另一个activity?
eg:
存:intent.putExtra("arrayList", dataList);
取(记得强制类型转换):
ArrayList<HashMap<String, Object>> dataList = new ArrayList<HashMap<String, Object>>();
dataList = (ArrayList<HashMap<String, Object>>) getIntent().getSerializableExtra("arrayList");
2. ArrayList<HashMap<String, Object>>如何更新键值对和删除键值对?
eg:
String[ ] name=
new
String[ ]{
"张三"
,
"李四"
,
"王五"
,
"赵六"
,
"霍七"
};
ArrayList<HashMap<String, Object>> arrayList =
new
ArrayList<HashMap<String, Object>>();
for
(
int
i=
0
; i <name.length ; i++){
HashMap<String, Object> map =
new
HashMap<String, Object>();
map.put(
"Name"
, name[ i ]);
arrayList.add(map);
}
// 修改制定key
for
(HashMap<String, Object> hashMap : arrayList)
{
if
(hashMap.get(
"Name"
).equals(
"王五"
))
{
hashMap.put(
"Name"
,
"小明"
);
}
}
// 官方推荐的删除方法
Iterator<HashMap<String, Object>> iterator = arrayList.iterator();
while
(iterator.hasNext())
{
if
(iterator.next().get(
"Name"
).equals(
"李四"
))
{
iterator.remove();
}
}
System.out.println(arrayList);
运行结果:
[{Name=张三}, {Name=小明}, {Name=赵六}, {Name=霍七}]
Map<String,Object> map1 = new HashMap<String,Object>();
map1.put("username",et_username.getText().toString().trim());
map1.put("password",et_password.getText().toString().trim());
Data.add(map1);
if(m!=null){
String username = m.get("username").toString().trim();
String password = m.get("password").toString().trim();
et_username.setText(username);
et_password.setText(password);
}else{
return;
}
}