Android:以编程方式查看.setID(int id) - 如何避免 ID 冲突?

Android: View.setID(int id) programmatically - how to avoid ID conflicts?(Android:以编程方式查看.setID(int id) - 如何避免 ID 冲突?)

本文介绍了Android:以编程方式查看.setID(int id) - 如何避免 ID 冲突?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I'm adding TextViews programmatically in a for-loop and add them to an ArrayList.

How do I use TextView.setId(int id)? What Integer ID do I come up with so it doesn't conflict with other IDs?

解决方案

According to View documentation

The identifier does not have to be unique in this view's hierarchy. The identifier should be a positive number.

So you can use any positive integer you like, but in this case there can be some views with equivalent id's. If you want to search for some view in hierarchy calling to setTag with some key objects may be handy.

这篇关于Android:以编程方式查看.setID(int id) - 如何避免 ID 冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Android:以编程方式查看.setID(int id) - 如何避免 ID 冲突?