이미지 뷰를 동적으로 채우는 PagerAdapter의 instantiateItem() 메소드에 대한 기본적인 예입니다.
@Override
public Object instantiateItem(final View pager, final int position)
{
//Note: if you do not have a local reference to the context make one and
//set it to the context that gets passed in to the constructor.
//Another option might be to use pager.getContext() which is how its
//done in the tutorial that you linked.
ImageView mImg = new ImageView(context);
/*Code to dynamically set your image goes here.
Exactly what it will be is going to depend on
how your images are stored.
In this example it would be if the images
are on the SD card and have filenames
with incrementing numbers like: (img0.png, img1.png, img2.png etc...)*/
Bitmap mBitmap = BitmapFactory.decodeFile(
Environment.getExternalStorageDirectory() + "/img" + position + ".png");
mImg.setImageBitmap(mBitmap);
((ViewPager) collection).addView(mImg, 0);
return mImg;
}
[갤러리 위젯] (http://developer.android.com/reference/android/widget/Gallery.html)은 이제 더 이상 사용되지 않습니다. 아마 ViewPager를 사용해야합니다. ViewPager를 사용하면서 질문을 편집하고 문제를 게시 할 수 있다면 해결 방법을 찾을 수 있습니다. – FoamyGuy
@Tim 나는 내 질문을 편집하고 확인했다. 동적으로 뷰를 생성하고 추가 할 수 있으며 클릭 리스너가 필요하다. –
ViewPager 만 사용하면 문제가 해결되고 호출기 뷰 내에서 지정해야한다. 실제로 레이아웃입니다) 표시하려는 항목 (특정보기에서) 클릭 이벤트를 처리합니다. – MobileEvangelist