カスタム ArrayAdapter で ListView を使用しています。リストはつぶやきの無限スクロールです。リストの更新は上から挿入されます。Twitterアプリとしての効果を得たい。「スクロールして更新」について話しているのではなく、更新後の位置を維持することです。
そのように機能するコードをいくつか実装しました。ここにあります:
// get the position of the first visible tweet.
// pausedCounter traces the number of tweets in the waiting line
final int idx = listView.getFirstVisiblePosition() + pausedCounter;
View first = listView.getChildAt(0);
int position = 0;
if (first != null)
position = first.getTop();
// here I update the listView with the new elements
for (Tweet[] tweets1 : pausedTweets)
super.updateTweets(tweets1);
final int finalPosition = position;
// this code maintain the position
listView.post(new Runnable() {
@Override
public void run() {
listView.setSelectionFromTop(idx, finalPosition);
}
});
このコードの問題は、一瞬 listView がリストの最初の要素に移動し、次にsetSelectionFromTopを開始して正しい位置に移動することです。
このような「ちらつき」が気になるので、消したいです。