Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在 App 运行期间对一些布局进行充气并将它们存储在类型的变量中View。我知道我可以Tag在充气后设置一个视图并检查它以检测它的类型,但是还有另一种方法来检测它吗?例如一种方法喜欢instanceof?
View
Tag
instanceof
尝试这样的事情
View yourView1=(View)findViewById(R.id.yourView1); boolean isMyView=false; try{ YourView yv=(YourView)yourView1; isMyView=true; } catch (ClassCastException e) { isMyView=false; e.printStackTrace(); } if(isMyView) { //OK it is yourView }