gpt4 book ai didi

java - 获取 xml 布局中项目的 ID

转载 作者:行者123 更新时间:2023-11-30 03:44:32 24 4
gpt4 key购买 nike

我有一行包含复选框和 2 个 TextView

我正在使用此代码重复自定义 xml 布局,它工作正常

但我想知道行中每个组件的每个 id 我的意思是(复选框的 id 和编辑 1 和 id edit2)

所以我可以和他们一起工作。

我还需要 for 循环来为 ids 创建这个实例。

为了让我的问题更清楚,我想像下面这样:

for ( int i = 0 ; i < 60 ; i++ ){

CheckBox "auto name here " = new (CheckBox) findViewById(R.id."the id of the current item in rep.xml layout or row ");

"auto name here".setChecked(true);

等等...

我在 for 循环中创建行的代码:

for (int i = 0; i<60 ; i++ ){

LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = (View) inflater.inflate(R.layout.rep, null);

tl.addView(view); // tl is table-layout instance
}

最佳答案

如果您需要添加 60 行,则不应使用循环和 TableLayout。

您应该改为使用带有适配器的 AdapterView 来保存数据并为您扩充行。这样做的众多好处之一是您能够声明在每一行中独立选中复选框时会发生什么。另一个是您将获得更好的性能,因为由于 convertView 回收,您永远不会一次在内存中拥有所有 60 行。

转到这里:http://developer.android.com/guide/topics/ui/binding.html有关 AdapterViews 的高级介绍。

研究 ListView 和 GridView 的示例。一旦您掌握了它们,请调整一些示例代码来扩充您自己的行,而不是给定的示例代码。

关于java - 获取 xml 布局中项目的 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15210867/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com