动态元素的ID以SETID(INT) - 机器人 [英] Dynamic element Id to setId(int) - Android

查看:208
本文介绍了动态元素的ID以SETID(INT) - 机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到的语法定义 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);

这篇关于动态元素的ID以SETID(INT) - 机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆