简体   繁体   English

动态获取ListView项目

[英]Get ListView Items dynamically

I've added some items dynamically like this: 我已经像这样动态添加了一些项目:

position = position + 1;
LinearLayout myLayout = (LinearLayout) findViewById(R.id.layoutTest);
TimePicker tpAux = new TimePicker(MyClass.this);
tpAux.setIs24HourView(true);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
                 layoutParams.setMargins(0, 12, 0, 0);
myLayout.addView(tpAux, position, layoutParams);

That code throws when a button is pressed. 按下按钮时将抛出该代码。

The question is, how to get all TimePicker (in this case) items that were created at run time when another button is pressed? 问题是,如何在按下另一个按钮时获取在运行时创建的所有TimePicker(在这种情况下)项目?

Thanks in advance! 提前致谢!

如何使用myLayout.getChildCount()和myLayout.getChildAt(int)?

Maybe use setTag() with a unique hashcode/int or something else? 也许将setTag()与唯一的哈希码/ int或其他方式一起使用? I can't really understand your question more than that. 除此以外,我真的无法理解您的问题。

From the docs: 从文档:

Sets a tag associated with this view and a key. 设置与此视图关联的标签和键。 A tag can be used to mark a view in its hierarchy and does not have to be unique within the hierarchy. 标签可用于在其层次结构中标记视图,并且在层次结构中不必唯一。 Tags can also be used to store data within a view without resorting to another data structure. 标签还可以用于在视图中存储数据,而无需诉诸其他数据结构。 The specified key should be an id declared in the resources of the application to ensure it is unique (see the ID resource type). 指定的密钥应该是在应用程序资源中声明的ID,以确保它是唯一的(请参阅ID资源类型)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM