androidandroid-viewandroid-identifiers

How to generate id in android randomly and programmatically?


I'm trying to generate random ids for views as shown in following screenshot. But it didn't work. It got null. How should I findViewById ?

enter image description here


Solution

  • use textView.setId(View.generateViewId()) introduced in API 17.