我有一个GridViewActivity,GridViewAdapter,FullScreenActivity和FullScreenImageAdapter。当我从GridView中单击图像时,转到FullScreenActivity并且它不会显示任何内容。我也从Drawable imgDisplay.setImageResource(R.drawable.a);
测试它没有发生。怎么了?我怎么解决?请!
在GridViewAdapter中;图像单击“侦听器”,
private class OnImageClickListener implements View.OnClickListener {
int _postion;
public OnImageClickListener(int position) {
this._postion = position;
}
@Override
public void onClick(View v) {
Intent i = new Intent(_activity, FullScreenActivity.class);
i.putExtra("position", _postion);
_activity.startActivity(i);
}
}
在FullScreenActivity中;从GridView获取位置,然后创建新的FullScreenImageAdapter
List<Item> mItems = new ArrayList<>();
int position = getIntent().getIntExtra("position", 0);
Log.i("Result", String.valueOf(position)); // return 0,1,2,3.. etc
adapter = new FullScreenImageAdapter(FullScreenActivity.this, mItems);
viewPager.setAdapter(adapter);
在FullScreenImageAdapter中;
public class FullScreenImageAdapter extends PagerAdapter {
List<Item> mItems = new ArrayList<>();
Activity _activity;
LayoutInflater inflater;
public FullScreenImageAdapter(Activity activity, List<Item> mItems) {
this._activity = activity;
this.mItems = mItems;
}
@Override
public int getCount() {
return mItems.size();
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == ((RelativeLayout) object);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
ImageView imgDisplay;
inflater = (LayoutInflater) _activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View viewLayout = inflater.inflate(R.layout.layout_fullscreen_image, container, false);
imgDisplay = (ImageView) viewLayout.findViewById(R.id.imgDisplay);
imgDisplay.setImageResource(R.drawable.a); // want to show from mItems List
((ViewPager) container).addView(viewLayout);
return viewLayout;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
((ViewPager) container).removeView((RelativeLayout) object);
}
}