这是来自我的自定义 PageAdapter:
public Object instantiateItem(View collection, int position) {
LayoutInflater inflater = (LayoutInflater) collection.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = null;
switch (position) {
case 0: view = dMngr.GetView(inflater);
break;
case 1: view = mMngr.GetView(inflater);
break;
case 2: view = cMngr.GetView(inflater);
break;
}
((ViewPager) collection).addView(view, 0);
return view;
}
这是cMngr.GetView代码:
public View GetView(LayoutInflater inflater){
View view = null;
if (showCamDetail){
view = inflater.inflate(R.layout.cam_view, null);
((Button)view.findViewById(R.id.button1)).setOnClickListener(myhandler2);
} else {
view = inflater.inflate(R.layout.cams_view, null);
((ImageView)view.findViewById(R.id.imageView1)).setOnClickListener(myhandler);
}
return view;
}
View.OnClickListener myhandler = new View.OnClickListener() {
public void onClick(View v) {
showCamDetail = true;
hPageAdapter.notifyDataSetChanged();
}
};
View.OnClickListener myhandler2 = new View.OnClickListener() {
public void onClick(View v) {
showCamDetail = false;
hPageAdapter.notifyDataSetChanged();
}
};
layout
仅当我滑动到第一页然后回到第三页时,此代码才会在第三页上更改。layout
单击我的ImageView
或后,我需要立即更改它Button
。