R
R
RaphaeI2014-12-05 10:35:07
Android
RaphaeI, 2014-12-05 10:35:07

How to programmatically assign a unique identifier?

TabHost is filled programmatically:

TabHost.TabSpec tabSpec;
     for (int i=0;i<db.sec.size();i++) {
    	 createTabs(i+10, db.sec.get(i));
   tabSpec = tabHost.newTabSpec("tag"+i+1);
   tabSpec.setIndicator("Секция "+(i+1));
         tabSpec.setContent(i+10);
         tabHost.addTab(tabSpec);       
     }

createTabs creates tables, which are given the identifier setId(i+10). There are elements on the main activity that are assigned id via xml: android:id="@+id/desc_switcher". Can two elements with the same id be obtained in this case?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Arthur Glyzin, 2015-02-18
@RaphaeI

aapt generates id for elements specified in xml starting from 0x00FFFFFF and above, so generating id below this number you should not cross.
PS since API 17 it is possible to generate a unique id programmatically via View.generateViewId()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question