handler.postDelayed()和timerTask
public static void scrollToListviewTop(final XListView listView)
{
listView.smoothScrollToPosition(0);
final Handler handler = new Handler();
handler.postDelayed(new Runnable()
{
@Override
public void run()
{
if (listView.getFirstVisiblePosition() > 0)
{
listView.smoothScrollToPosition(0);
handler.postDelayed(this, 100);
}
}
}, 100);
}
public class TimeTaskScroll extends TimerTask {
private XListView listView;
public TimeTaskScroll(XListView listView){
this.listView = listView;
}
private Handler handler = new Handler() {
public void handleMessage(android.os.Message msg) {
listView.smoothScrollToPosition(0);
};
};
@Override
public void run() {
Message msg = handler.obtainMessage();
handler.sendMessageDelayed(msg, 2000);
}
}
new TimerTask().run();