这是MainActivitypublic class MainActivity extends Activity implements
AdapterView.OnItemSelectedListener {
private Gallery photo;
private Gallery details;
private PhotoAdapter photoAdapter;
private DetailsAdapter detailsAdapter; protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.audio_player);
setupViews();
} private void setupViews() {
PersonService ps = new PersonService(this);
List<Person> list = ps.getData(); photo = (Gallery) findViewById(R.id.gallery);
photoAdapter = new PhotoAdapter(this,list);
photo.setAdapter(photoAdapter);
photo.setOnItemSelectedListener(this);

details = (Gallery) findViewById(R.id.gallery2);
detailsAdapter = new DetailsAdapter(this,list);
details.setAdapter(detailsAdapter);
details.setOnItemSelectedListener(this);

} public void onItemSelected(AdapterView<?> parent, View view, int position,
long id) {

if (parent == details) {
// 更新第一个Gallery
detailsAdapter.notifyDataSetChanged(position);
// photo.setSelection(position);
Log.i("MainActivity", view.getId()+"");
} else if (parent == photo) {
// 更新第二个Gallery
photoAdapter.notifyDataSetChanged(position);
// details.setSelection(position);
Log.i("MainActivity", view.getId()+"");
}
} public void onNothingSelected(AdapterView<?> parent) {

}
}这是第一个gallery的adapter
public class PhotoAdapter extends BaseAdapter { private Context context;
private List<Person> list;
private Person person;

public PhotoAdapter(Context context,List<Person> list) {
this.context = context;
this.list = list;
} public int getCount() {
if (list != null) {
return list.size();
}
return 0;
} public Object getItem(int position) {
if (list != null) {
return list.get(position);
}
return null;
} public long getItemId(int position) {
return position;
} public View getView(int position, View convertView, ViewGroup parent) {
person = list.get(position);
ImageView iv = new ImageView(context);
iv.setLayoutParams(new Gallery.LayoutParams(100, 100));
iv.setAdjustViewBounds(true);
iv.setImageBitmap(person.photo);
return iv;
} public void notifyDataSetChanged(int position) {

Log.i("PhotoAdapter","notifyDataSetChanged: "+position);
super.notifyDataSetChanged();
}

}这是第二个gallery的adapter
public class DetailsAdapter extends BaseAdapter {
private Context mContext;
private List<Person> list;
private LayoutInflater inflater ;
private Person person = null; public DetailsAdapter(Context context,List<Person> list) {
this.inflater = LayoutInflater.from(context);
this.mContext = context;
this.list = list;
} public int getCount() {
if (list != null) {
return list.size();
}
return 0;
} public Object getItem(int position) {
if (list != null) {
return list.get(position);
}
return null;
} public long getItemId(int position) {
return position;
} public View getView(int position, View convertView, ViewGroup parent) {
person = list.get(position); // 
ViewHolder mView = null;
if(convertView==null){
convertView = inflater.inflate(R.layout.list_item, null);
mView = new ViewHolder();
mView.listLorder = (ImageView)convertView.findViewById(R.id.list_order);
mView.textWebsite = (TextView)convertView.findViewById(R.id.text_website);
}else{
mView = (ViewHolder)convertView.getTag();
}
mView.listLorder.setImageBitmap(person.photo);
mView.textWebsite.setText(person.name);
return convertView;
} public void notifyDataSetChanged(int position) {
Log.i("DetailsAdapter","notifyDataSetChanged: "+position);
super.notifyDataSetChanged();
}

public final class ViewHolder{
public ImageView listLorder;
public TextView textWebsite;
}
}这是模拟数据的Service,虽然假,我也粘上去了
public class PersonService {

private Context mContext;

public PersonService(Context context){
this.mContext = context;
}

public List<Person> getData(){
Drawable drawable1 = mContext.getResources().getDrawable(R.drawable.bg_admin);
Bitmap bitmap1 = BitmapUtil.drawableToBitmap(drawable1);
Drawable drawable2 = mContext.getResources().getDrawable(R.drawable.person);
Bitmap bitmap2 = BitmapUtil.drawableToBitmap(drawable2);
Drawable drawable3 = mContext.getResources().getDrawable(R.drawable.create_shortcut_contacts);
Bitmap bitmap3 = BitmapUtil.drawableToBitmap(drawable3);
Drawable drawable4 = mContext.getResources().getDrawable(R.drawable.create_shortcut_dial);
Bitmap bitmap4 = BitmapUtil.drawableToBitmap(drawable4);
Drawable drawable5 = mContext.getResources().getDrawable(R.drawable.create_shortcut_mms);
Bitmap bitmap5 = BitmapUtil.drawableToBitmap(drawable5);
Drawable drawable6 = mContext.getResources().getDrawable(R.drawable.default_avatar_big);
Bitmap bitmap6 = BitmapUtil.drawableToBitmap(drawable6);
List<Person> list = new ArrayList<Person>();
Person person1 = new Person("sky1",""+1,bitmap1);
list.add(person1);
Person person2 = new Person("sky2",""+2,bitmap2);
list.add(person2);
Person person3 = new Person("sky3",""+3,bitmap3);
list.add(person3);
Person person4 = new Person("sky4",""+4,bitmap4);
list.add(person4);
Person person5 = new Person("sky5",""+5,bitmap5);
list.add(person5);
Person person6 = new Person("sky6",""+6,bitmap6);
list.add(person6);
Person person7 = new Person("sky7",""+7,bitmap1);
list.add(person7);
Person person8 = new Person("sky8",""+8,bitmap1);
list.add(person8);
Person person9 = new Person("sky9",""+9,bitmap1);
list.add(person9);
return list;

}}
这是模拟数据的封装类 Person
public class Person {

public String name;

public String number;

public Bitmap photo;

public Person(){}

public Person(String name , String number ,Bitmap photo){
this.name = name;
this.number = number;
this.photo = photo;
}}这是主要布局文件<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
  android:layout_width="fill_parent" 
  android:layout_height="fill_parent">
  

<Gallery android:id="@+id/gallery" 
   android:layout_width="fill_parent" 
 android:layout_height="300dp" 
 android:layout_alignParentTop="true"  
 android:gravity="center_horizontal" 
 android:spacing="16dp"  
 android:unselectedAlpha="0.5" />

<Gallery android:id="@+id/gallery2"  
android:background="#FFF" 
android:layout_width="fill_parent"  
android:layout_height="100dp" 
  android:layout_below="@id/gallery" 
android:layout_alignParentLeft="true"  
android:gravity="center_vertical" 
android:spacing="16dp"  
android:unselectedAlpha="0.5" />

</RelativeLayout>这是第二个gallery的布局文件list_item<?xml version="1.0" encoding="utf-8"?>  
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/list_item_parent_layout"
>
<ImageView android:id="@+id/list_order"
android:layout_width="match_parent" 
android:layout_height="80dp"
android:src="@drawable/bg_admin">
</ImageView>
<TextView android:id="@+id/text_website"
android:layout_width="match_parent"
android:layout_height="20dp"
></TextView></LinearLayout>不知道怎么联动起来,我用的集合是list,具体demo我上传到csdn上了啊,thx