一个页面有ImageView 头像设置 和一个按钮 当单击按钮时 跳转到第二个页面 此页面中有GridView 好多图片 选择一张 这时第一个页面的头像就变成此张图片核心方法 第一个Activity中 Intent intent=new Intent(this,xxx.class); startActivityForResult(intent,1);//带返回结果的跳转 并在此Activity中 重写 onActivityResult()方法 if(responseCode==CODE){ 从Intent data 中获取第二个Activity返回的值 String s= data.getStringExtra("img"); 解析来将s转为int类型 int num=Integer.parseInt(s);并设置给ImageView imgView.setImageResource(num); }第二个Activity中在GridView的监听事件中gView.SetOnItemClikeListener(){ onItemClick(AdapterView<?> parent, View view, int position, long id) {Intent intent=getIntent();intent.putExtra("key",imgs[position]);//此处是将被点击的图片通过intent意图返回setResult(结果码,intent);finish(); 具体代码如下:布局文件一: 布局文件二: 布局文件三: mainActivity:import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.widget.ImageView;public class MainActivity extends Activity {private ImageView imgView;//int[] img={R.drawable.sample_0,R.drawable.sample_0,R.drawable.sample_1,R.drawable.sample_2,R.drawable.sample_3,R.drawable.sample_4,R.drawable.sample_5,R.drawable.sample_6,R.drawable.sample_7};@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);imgView = (ImageView) findViewById(R.id.imgView);}public void onClick(View v){Intent intent=new Intent(this,SendActivity.class);startActivityForResult(intent, 1);}@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {// TODO Auto-generated method stubsuper.onActivityResult(requestCode, resultCode, data);if(requestCode==1){//如果请求码 是1 说明结果是 Intent intent=new Intent(this,SendActivity.class)中SendActivity传回来的String num = data.getStringExtra("img");int i = Integer.parseInt(num);imgView.setImageResource(i);}}}第二个Activity:import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.widget.AdapterView;import android.widget.AdapterView.OnItemClickListener;import android.widget.GridView;public class SendActivity extends Activity {int num=0;private GridView gView;List<Map> list;int[] img={R.drawable.sample_0,R.drawable.sample_0,R.drawable.sample_1,R.drawable.sample_2,R.drawable.sample_3,R.drawable.sample_4,R.drawable.sample_5,R.drawable.sample_6,R.drawable.sample_7};@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_send);gView = (GridView) findViewById(R.id.gView);list=new ArrayList<Map>();for(int i=0;i<8;i++){Map m1=new HashMap();m1.put("imag", img[i]);m1.put("name", "图片"+i);list.add(m1);}MyAdapter adapter=new MyAdapter(list,this);gView.setAdapter(adapter);gView.setOnItemClickListener(new OnItemClickListener() {int num=0;@Overridepublic void onItemClick(AdapterView<?> parent, View view,int position, long id) {// TODO Auto-generated method stub //注意是 getIntent// Intent data =getIntent(); Intent data=new Intent();//为什么 new 也可以 data.putExtra("img",img[position]+"");//要将数字转成字符串 setResult(2, data); finish();}});}}适配器:import java.util.List;import java.util.Map;import android.content.Context;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.BaseAdapter;import android.widget.ImageView;import android.widget.TextView;public class MyAdapter extends BaseAdapter {List<Map> list;Context context;public MyAdapter(List<Map> list,Context context){this.list=list;this.context=context;}@Overridepublic int getCount() {// TODO Auto-generated method stubreturn list.size();}@Overridepublic Object getItem(int position) {// TODO Auto-generated method stubreturn list.get(position);}@Overridepublic long getItemId(int position) {// TODO Auto-generated method stubreturn position;}@Overridepublic View getView(int position, View convertView, ViewGroup parent) {// TODO Auto-generated method stubViewHolder vHolder;if(convertView==null){vHolder=new ViewHolder();convertView=LayoutInflater.from(context).inflate(R.layout.item_grid, parent,false);vHolder.imgView=(ImageView) convertView.findViewById(R.id.imgView);vHolder.textView=(TextView) convertView.findViewById(R.id.textView);convertView.setTag(vHolder);}else{vHolder=(ViewHolder) convertView.getTag();}vHolder.imgView.setImageResource((Integer) list.get(position).get("imag"));vHolder.textView.setText(list.get(position).get("name").toString());return convertView;}public class ViewHolder{ImageView imgView;TextView textView;}}