1、正向传值
第一个页面通过Intent传值
Intent intent = new Intent(MainActivity.this, DetailActivity.class); currnetPostion = position; intent.putExtra("name", aData.get(position).getName()); intent.putExtra("phone", aData.get(position).getPhoneNumber()); intent.putExtra("iconimage", aData.get(position).getItemIcon()); //这种启动方式:startActivity(intent);并不能返回结果 //startActivity(intent); startActivityForResult(intent, 1000);
第二个页面接收传值
Intent getIntent = getIntent(); editTextName.setText(getIntent.getStringExtra("name")); editTextNum.setText(getIntent.getStringExtra("phone"));
2、反向传值
第二个页面反向传值
Intent backIntent = new Intent(); backIntent.putExtra("name", editTextName.getText().toString()); backIntent.putExtra("phone", editTextNum.getText().toString()); setResult(1001, backIntent); finish();
第一个页面接收传值
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == 1001 && requestCode == 1000) { aData.get(currnetPostion).setName(data.getStringExtra("name")); aData.get(currnetPostion).setPhoneNumber(data.getStringExtra("phone")); // 更新适配器 aAdatper = new AddressAdapter((LinkedList<AddressItem>) aData, aContext); listPerson.setAdapter(aAdatper); } }