How to generate id in android randomly and programmatically?

Zin Win Htet picture Zin Win Htet · Aug 5, 2014 · Viewed 15.5k times · Source

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

Answer

Montassir Ld picture Montassir Ld · Jan 4, 2017

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