【发布时间】:2014-08-24 20:19:03
【问题描述】:
我有一个由数组 adpater 填充的列表视图。用户从活动 a 开始,单击列表视图中的项目后,将转到活动 b,他们可以在其中编辑他们单击的项目。用户返回 A 后,来自 B 的已编辑项目通过 Intent 发送回 A。我希望将在 A 中单击的原始项目替换为从 B 的 Intent 接收到的数据。
ArrayAdapter<Comment> adapter = new ArrayAdapter<Comment>(this,
android.R.layout.simple_list_item_1, values);
// setListAdapter(adapter);
final ListView listView = (ListView) findViewById(R.id.list);
listView.setAdapter(adapter);
//intent receiving data from Activity B; I want to add in statement to change the original item clicked to this new String, edit;
Bundle fromedit = getIntent().getExtras();
if (fromedit != null) {
String edit = fromedit.getString("BENG");
int ps = fromedit.getInt("POSITION");
}
//onclicklistener for the listview
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Intent intent = new Intent(Notes.this, EditNote.class);
intent.putExtra("KEY", values.get(position).toString());
intent.putExtra("POSITION", position);
startActivity(intent);
}
});
谢谢!
【问题讨论】:
标签: android listview adapter onitemclicklistener