ギャラリーウィジェットを使用してカレンダーを作成しようとしています。特定の月のビューの作成を処理するmonthviewクラスがあります。私のMonthGalleryクラスは、子ビューとしてmonthviewを使用し、monthviewadapterはmonthgalleryのmonthviewを作成します。私が抱えている問題は、ユーザーが前月または翌月にスクロールまたはフリングしているときに、前月と翌月にアダプターを更新しようとしていることです。ギャラリーonItemSelectedListenerで指定された位置を使用して、この位置に応じてアダプターの前面と背面に月を追加します。例えば:
OnItemSelectedListener mGalleryOnItemSelectedListener = new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterview, View view, int position, long id) {
MonthView mv = (MonthView) view;
int month = mv.getMonth();
int year = mv.getYear();
updateMonthBar(month, year);
if ((position + 1) == mMonthViewGallery.getCount()) {
if (Calendar.DECEMBER == month) {
mMonthViewAdapter.addView(Calendar.JANUARY, year + 1);
} else {
mMonthViewAdapter.addView(month + 1, year);
}
mMonthViewGallery.setSelection(position);
}
if (0 == position) {
if (Calendar.JANUARY == month) {
mMonthViewAdapter.addViewToFront(Calendar.DECEMBER, year - 1);
} else {
mMonthViewAdapter.addViewToFront(month - 1, year);
}
mMonthViewGallery.setSelection(1);
}
}
問題
ユーザーが別の月にスクロールしてから最初の月にスクロールしようとすると、ギャラリーは自動的に次の選択にスナップしません。アダプタでは、addView(int month、int year)が呼び出されると、notifyDataSetChanged()が呼び出され、ギャラリーが前月または翌月に更新されますが、これにより、ゆっくりとスクロールしているときに予期しない「スナップ」が発生するようです。スクロールがスムーズになるようにこれを構成する方法がわからないだけです。
編集
私は現在Gallery.setCallbackDuringFling(false)を使用していますが、ギャラリーのスクロール中にonitemselectedコールバックを無効にし、スクロールが完了したらonitemselected()を呼び出す方法はありますか?