动态元素的ID以SETID(INT) - 机器人机器人、元素、动态、ID

2023-09-07 01:50:02 作者:呀~土豆

我看到的语法定义 SETID(INT) findViewByID(INT)

但是,我们如何使用 findViewById(R.id.row1)

我尝试使用这样的:

Object1.setId(的Integer.parseInt(重复));

这表明没有错误,但力跑了。

It showed no error but dint run too.

什么是错的?如果 SETID(INT)需要 INT 键,并通过整数它,那么什么是错误。 当我评论了程序运行的语句。

What is wrong? If setId(int) takes int and and passing integer to it, then what is the error. When I commented the statement the program runs.

如果 findViewById(INT)接受整数,然后是 R.id.object_id 是一个整数? 如果是的话,它是如何与 findViewById()映射? 如果没有,那么如何使用 findViewById SETID

and if findViewById(int) accepts integers then is R.id.object_id is an integer? if yes, how is it mapped with the findViewById()? if No, then how to use findViewById and setId.

推荐答案

这不建议将您的对象标识自己,findViewById使访问您的R舱,其中包含指向您的XML项目的ID。

It's not recommended to set your object id yourself , findViewById make access to your R class that contains pointers to your XML items id.

当你定义你的XML布局文件中的一个ID像

when you define an id in your Xml Layout file like

android:id="@+id/txtyourId"

在编译的时候编译器创建一个参照R舱您的XML项目的布局,你可以从你的java code。通过findViewById访问

in compile time compiler create a reference to your XML Item layout in R class that you can access it from your java code by findViewById

View YourItem = (View)this.findViewById(R.id.txtyourId);