简体   繁体   English

如何在视图上存储数据?

[英]How to store data on a View?

I'm making a project that will dynamically add Views ( RelativeLayouts ) to a GridLayout .我正在制作一个将视图( RelativeLayouts )动态添加到GridLayout的项目。 The only problem is that I need to get the row and column of that View I have clicked on to dynamically add or remove a View .唯一的问题是我需要获取我单击的View的行和列以动态添加或删除View I know that in Javascript and html I can add a data attribute.我知道在Javascripthtml我可以添加一个数据属性。 Is there something like that for android? android 有类似的东西吗?

If there are also other ways of doing it, I will appreciate the help如果还有其他方法,我将不胜感激

You can set a tag to a view with .setTag() method, and retrieve that with .getTag() .您可以使用.setTag()方法将标签设置为视图,并使用.getTag()检索它。

You need to cast that tag when you use getTag() to the data type you put onto it with setTag() .当您使用getTag()时,您需要将该标签转换为您使用setTag()放入它的数据类型。

This is the a very useful question that might also help you. 是一个非常有用的问题,也可能对您有所帮助。

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

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