Note that there are some explanatory texts on larger screens.

plurals
  1. POBunch of questions about View ids
    primarykey
    data
    text
    <p>i would like to ask a lot of questions about how this whole id system works in android. I looked up the View documentation, but the description was too shallow for my taste.</p> <ol> <li><p>Is there a pattern, how the IDE (Eclipse/Netbeans) generates the ids when i use <code>android:id="@+id/..."</code>? Or is it completely random?</p></li> <li><p>If i set ids programmatically, then will it be found by the Context classes <code>findViewById()</code> function?</p></li> <li><p>If the answer for the previous question is yes, then if i want to create a large amount of Views, but i want them to have distinct ids for later identification, then wich one is better to use? (To answer this question, it would be really useful to know the answer for the first two)</p> <p>For example generating random ids in the largest possible range:</p> <pre><code>Random random = new Random(); for(int i=0; i&lt;100; i++) { View view = new View(someContext); view.setId(random.nextInt(Integer.MAX_VALUE)); } </code></pre> <p>Or setting the ids in some sort of order, for example:</p> <pre><code>final int addToId = 5670; for(int i=0; i&lt;100; i++) { View view = new View(someContext); view.setId(i+addToId); } </code></pre></li> <li>Also i would like to know, what happens, when you use a LayoutInflater for example to populate a <code>ListView</code> using a pre-defined xml layout for every item in the list. Then you get your sub-views in the <code>getView()</code> function by the <code>findViewById()</code>. So i assume, that all the identical Views across your listitems have the same id. If so, then is it a good practice to use the <code>tag</code> attribute to distinguish the items in an inflated layout?</li> </ol> <p><strong>Any clear explanation for these question would be highly appreciated!</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload