Skip to content

Instantly share code, notes, and snippets.

public class MyFragment {
boolean loaded;
private void maybeLoad() {
if (!loaded && getUserVisibleHint()) {
loaded = true;
loadMyData();
}
}
@Override
@chrisbanes
chrisbanes / SystemUiHelper.java
Last active November 5, 2024 13:50
SystemUiHelper
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@ikew0ng
ikew0ng / ListViewUtils.java
Created June 6, 2014 08:04
Smoothly scroll listView to specified position.
public class ListViewUtils {
public static final int SCROLL_DURATION = 150;
private ListViewUtils() {}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static void scrollListView(final ListView listView, final int position) {
if (CommonUtils.hasHoneycomb()) {
listView.smoothScrollToPositionFromTop(position, 0);
listView.postDelayed(new Runnable() {