【发布时间】:2013-02-06 06:32:31
【问题描述】:
我看到了setId(int)和findViewByID(int)的语法定义。
但是我们如何使用findViewById(R.id.row1)
我试过用这个:
Object1.setId(Integer.parseInt("repeat"));
它没有显示错误,但也运行了。
怎么了?如果setId(int) 接受int 并将integer 传递给它,那么错误是什么。 When I commented the statement the program runs.
如果findViewById(int) 接受整数,那么R.id.object_id 是整数吗?
如果是,它是如何与findViewById() 映射的?
如果否,那么如何使用findViewById 和setId。
【问题讨论】:
-
您正在将字符串值解析为整数。它会给你错误 NumberFormatException。您可能一直在使用 try catch 语句并且没有分配 id。现在您正在使用 findview by id 访问元素