を使用する場合、ImageSwitcherこれは非常に簡単なことです。Galleryを 2 つに置き換えて、Buttonsそれらを にリンクする必要がありImageSwitcherます。
private int[] mImageIds= //.. the ids of the images to use
private int mCurrentPosition = 0; // an int to monitor the current image's position
private Button mPrevious, mNext; // our two buttons
この 2つにはbuttons2 つのonClick コールバックがあります。
public void goPrevious(View v) {
mCurrentPosition -= 1;
mViewSwitcher.setImageResource(mImageIds[mCurrentPosition]);
// this is required to kep the Buttons in a valid state
// so you don't pass the image array ids boundaries
if ((mCurrentPosition - 1) < 0) {
mPrevious.setEnabled(false);
}
if (mCurrentPosition + 1 < mImageIds.length) {
mNext.setEnabled(true);
}
}
public void goNext(View v) {
mCurrentPosition += 1;
mViewSwitcher.setImageResource(mImageIds[mCurrentPosition]);
// this is required to kep the Buttons in a valid state
// so you don't pass the image array ids boundaries
if ((mCurrentPosition + 1) >= mImageIds.length) {
mNext.setEnabled(false);
}
if (mCurrentPosition - 1 >= 0) {
mPrevious.setEnabled(true);
}
}
Buttonメソッドの前のものを無効にすることを忘れないでくださいonCreate(配列の最初の画像から開始するため)。