I recently ran into the same problem. The first time I used LinearLayout, so the first answer was just good - setting each view identifier to 0 was not a problem.
However, the second time I used RelativeLayout - set id to 0, the whole view just broke, since it is positioned as "leftTo: some_id", etc.
I tried a little, and it turned out that adding a view to its container AFTER installing all its components solves the problem (we just need to inflate it with a parameter that prevents adding a bloated layout to its parent element). The idea is to have an overestimated view outside any other view containing components with the same identifier, so findViewById can only find one that interests us, and not the one that was pumped up earlier.
ViewGroup inflatedLayout = (ViewGroup) layoutInflater.inflate(R.layout.some_id, mDirectChildInScrollView, false); ImageView imageView = (ImageView) inflatedLayout.findViewById(R.id.image_view); ... do your stuff here ... mDirectChildInScrollView.addView(inflatedLayout);
You can use the ViewHolder template to access the desired item later without calling findViewById.
source share