将数据放到intent对象中进行传递:
lvList = (ListView) findViewById(R.id.lv_list);
final ArrayList<HashMap<String, String>> contact= readContact();
lvList.setAdapter(new SimpleAdapter(this, contact, R.layout.contact_list_item, new String[]{"name","phone"},
new int[]{R.id.tv_name,R.id.tv_phone}));
lvList.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// TODO Auto-generated method stub
String phone = contact.get(position).get("phone"); //读取当前的item的电话; 将这个值放到Intent中。
Intent intent = new Intent();
intent.putExtra("phone", phone); //将电话放到intent对象中;
setResult(1, intent); // 将数据传递到上一个页面。
finish(); //将页面关闭掉。
}
});
本文介绍了一种在Android应用中通过Intent对象传递数据的方法。具体展示了如何从ListView中选择一项,并将其电话号码信息封装到Intent中,以便在不同Activity之间进行传递。
756

被折叠的 条评论
为什么被折叠?



