Skip to content

Commit 75ac4e8

Browse files
adampAndroid (Google) Code Review
authored andcommitted
Merge "Fix a bug with deferred position scrolling in lists while data changes are pending" into jb-dev
2 parents a587b89 + 161abf3 commit 75ac4e8

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

core/java/android/widget/AbsListView.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
579579
private InputConnectionWrapper mPublicInputConnection;
580580

581581
private Runnable mClearScrollingCache;
582+
Runnable mPositionScrollAfterLayout;
582583
private int mMinimumVelocity;
583584
private int mMaximumVelocity;
584585
private float mVelocityScale = 1.0f;
@@ -1910,6 +1911,7 @@ void resetList() {
19101911
removeAllViewsInLayout();
19111912
mFirstPosition = 0;
19121913
mDataChanged = false;
1914+
mPositionScrollAfterLayout = null;
19131915
mNeedSync = false;
19141916
mOldSelectedPosition = INVALID_POSITION;
19151917
mOldSelectedRowId = INVALID_ROW_ID;
@@ -4248,11 +4250,11 @@ void start(final int position) {
42484250

42494251
if (mDataChanged) {
42504252
// Wait until we're back in a stable state to try this.
4251-
post(new Runnable() {
4253+
mPositionScrollAfterLayout = new Runnable() {
42524254
@Override public void run() {
42534255
start(position);
42544256
}
4255-
});
4257+
};
42564258
return;
42574259
}
42584260

@@ -4299,11 +4301,11 @@ void start(final int position, final int boundPosition) {
42994301

43004302
if (mDataChanged) {
43014303
// Wait until we're back in a stable state to try this.
4302-
post(new Runnable() {
4304+
mPositionScrollAfterLayout = new Runnable() {
43034305
@Override public void run() {
43044306
start(position, boundPosition);
43054307
}
4306-
});
4308+
};
43074309
return;
43084310
}
43094311

@@ -4376,11 +4378,11 @@ void startWithOffset(final int position, int offset, final int duration) {
43764378
if (mDataChanged) {
43774379
// Wait until we're back in a stable state to try this.
43784380
final int postOffset = offset;
4379-
post(new Runnable() {
4381+
mPositionScrollAfterLayout = new Runnable() {
43804382
@Override public void run() {
43814383
startWithOffset(position, postOffset, duration);
43824384
}
4383-
});
4385+
};
43844386
return;
43854387
}
43864388

core/java/android/widget/GridView.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,10 @@ protected void layoutChildren() {
12751275

12761276
mLayoutMode = LAYOUT_NORMAL;
12771277
mDataChanged = false;
1278+
if (mPositionScrollAfterLayout != null) {
1279+
post(mPositionScrollAfterLayout);
1280+
mPositionScrollAfterLayout = null;
1281+
}
12781282
mNeedSync = false;
12791283
setNextSelectedPositionInt(mSelectedPosition);
12801284

core/java/android/widget/ListView.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,6 +1691,10 @@ protected void layoutChildren() {
16911691

16921692
mLayoutMode = LAYOUT_NORMAL;
16931693
mDataChanged = false;
1694+
if (mPositionScrollAfterLayout != null) {
1695+
post(mPositionScrollAfterLayout);
1696+
mPositionScrollAfterLayout = null;
1697+
}
16941698
mNeedSync = false;
16951699
setNextSelectedPositionInt(mSelectedPosition);
16961700

0 commit comments

Comments
 (0)