1

I have to impliment the same logic to generate unique ids in my project for different component created at runtime as R.java does. Some one can help me

Jawad
  • 21
  • 2

1 Answers1

2

If you only need unique ID's at runtime than maybe a singleton which handles the ids can be enough.

public class UidUtils {

    private UidUtils() {}

    /**
     * A unique identifier.
     */
    private static int uid = 1;

    /**
     * Deliver the next uid.
     * 
     * @return The next uid.
     */
    public static int getNextUid() {
        return ++uid;
    }

}
FrVaBe
  • 47,963
  • 16
  • 124
  • 157