Search code examples
androidcustom-controlscentercoverflow

Android scrollby() blocks my UI


I have used custom coveflow, everything works fine when i load small amount of data, but it doesn't work with large amount of data,

check it out my below code

if (mAdapter == null || mAdapter.getCount() == 0)
    throw new IllegalStateException(
            "You are trying to scroll container with no adapter set. Set adapter first.");
if (mLastCenterItemIndex != -1) {
    final int lastCenterItemPosition = (mFirstItemPosition + mLastCenterItemIndex)
            % mAdapter.getCount();
    final int di = lastCenterItemPosition - position;
    final int dst = (int) (di * mCoverWidth * mSpacing);
    mScrollToPositionOnNextInvalidate = -1;
    scrollBy(-dst, 0);
} else {
    mScrollToPositionOnNextInvalidate = position;
}
invalidate();

i have used this code to move my item to center of the tablet, now i am gng to explain my view, in one activity half of my screen occupies coverflow and other half occupies mapview, when i click map marker icon i need to move particular item to center of my screen in coverflow, so basically my coverflow and map sync, the changes must affect both,

it works perfectly when i load small amount of data, but now i tried to load 11000 records when i click marker then my UI gets blocked becuase of scrollby in Coverflow, can you suggest any idea to move my item center?? or is there any method which doesn't affect UI

All suggestion are most welcome Thanks


Solution

  • Just include your code in

    new Thread(new Runnable() {
          public void run () {
             //.........
          }
    }).start();
    

    or load items by parts