A backport of generateViewId() to API 10+
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CustomGenerateViewId { | |
private static final AtomicInteger nextGeneratedId = new AtomicInteger(1); | |
public static int customGenerateViewId() { | |
for (; ; ) { | |
final int result = nextGeneratedId.get(); | |
// aapt-generated IDs have the high byte nonzero; clamp to the range under that. | |
int newValue = result + 1; | |
if (newValue > 0x00FFFFFF) { | |
newValue = 1; // Roll over to 1, not 0. | |
} | |
if (nextGeneratedId.compareAndSet(result, newValue)) { | |
return result; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment