我看到了语法定义setId(int)
and findViewByID(int)
.
但我们如何使用findViewById(R.id.row1)
我尝试使用这个:
Object1.setId(Integer.parseInt("repeat"));
它没有显示错误,但也不要运行。
怎么了?如果setId(int)
takes int
和并且经过integer
到它,那么错误是什么。When I commented the statement the program runs.
and if findViewById(int)
接受整数则为R.id.object_id
是一个整数?
如果是,它是如何与findViewById()
?
如果否,那么如何使用findViewById
and setId
.
不建议您自己设置对象 id,findViewById 可以访问包含指向 XML 项目 id 的指针的 R 类。
当您在 Xml 布局文件中定义 id 时,例如
android:id="@+id/txtyourId"
在编译时编译器中创建对 R 类中的 XML Item 布局的引用,您可以通过 findViewById 从 java 代码访问它
View YourItem = (View)this.findViewById(R.id.txtyourId);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)