In my app I am creating Views
- in this case an EditText
- dynamically. But every View
I add needs to have a unique id.
EditText editText = new EditText(context);
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
editText.setLayoutParams(params);
// Which value am I supposed to use here?
editText.setId(value);
layout.addView(editText);
I am afraid of conflicts if I assign a random value and I cannot think of any way to generate ids without the possibility of conflicts.
Please not that I know that one can define a fixed set of ids in res/values/ids.xml, but that is not what I want! I need to create the ids dynamically! I have no idea how many I need.
So is there any safe way to generate ids?