title: How to assign unique ids to dynamically created Views?
body: <p>In my app I am creating <code>Views</code> - in this case an <code>EditText</code> - dynamically. But every <code>View</code> I add needs to have a unique id.</p>
  
  <pre><code>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);
  </code></pre>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>So is there any safe way to generate ids?</p>