ArrayList<HashMap<String, String>> taskItems = new ArrayList<>();
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//neue Oberflaeche starten
Intent in = new Intent(this, SingleTaskList.class);;
in.putExtra("taskItems", taskItems.get(position));
in.putExtra("position",position);
startActivityForResult(in, 200);
}
如果用户单击某个项目,它将把
position
上的地图提供给第二个Activity。在那里,用户可以在
EditText
上书写。单击“保存”按钮后,它将为地图提供EditText
中编写的文本。saveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent returnIntent = new Intent();
returnIntent.putExtra("taskItems",taskItems);
returnIntent.putExtra("position",position);
setResult(RESULT_OK, returnIntent);
finish();
}
});
在这里,我从第二个活动中得到了结果:
@Override
protected void onActivityResult(int requestCode,int resultCode, Intent data) {
if(requestCode == 200) {
if(resultCode == RESULT_OK) {
int position = data.getIntExtra("position",0);
}
if (resultCode == RESULT_CANCELED) {
}
}
}
如何在第一次给定的位置上替换地图?
我希望我的问题很清楚。
亲切的问候。
最佳答案
@Override
protected void onActivityResult(int requestCode,int resultCode, Intent data) {
if(requestCode == 200) {
if(resultCode == RESULT_OK) {
int position = data.getIntExtra("position",0);
HashMap<String,String> items = (HashMap<String,String>) data.getSerializableExtra("taskItems");
taskItems.set(position, items);
adapter.notifyDatasetChanged();
}
if (resultCode == RESULT_CANCELED) {
}
}
}