My app uses a ListView in portraint mode which is simply switches to Gallery in landscape mode. Both of them use one BaseAdapter. This looks like shown below.
setContentView(R.layout.somelayout);
orientation = getResources().getConfiguration().orientation;
if ( orientation == Configuration.ORIENTATION_LANDSCAPE )
{
Gallery gallery = (Gallery)findViewById( R.id.somegallery );
gallery.setAdapter( someAdapter );
gallery.setOnItemClickListener( new OnItemClickListener() {
@Override
public void onItemClick( AdapterView<?> parent, View view,
int position, long id ) {
onClick( position );
}
});
}
else
{
setListAdapter( someAdapter );
getListView().setOnScrollListener(this);
}
To handle scrolling events I've inherited my own widget from Gallery and override onFling(). Here's the layout.xml:
<view
class="package$somegallery"
android:id="@+id/somegallery"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
</view>
and code:
public static class somegallery extends Gallery
{
private Context mCtx;
public somegallery(Context context, AttributeSet attrs)
{
super(context, attrs);
mCtx = context;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
( (CurrentActivity)mCtx ).onScroll();
return super.onFling(e1, e2, velocityX, velocityY);
}
}