ListView中的隐藏字段传递变量
我正在尝试构建我的第一个应用程序,它几乎从网上的 XML 文件创建一个列表。一旦我点击一个列表项,它就会打开另一个活动并访问另一个在线生成的 XML 文件,其中包含该项目的详细信息。 我设法使列表以及包含详细信息的第二个活动窗口正常工作。剩下要做的唯一一件事就是将 id 从一个活动传递到另一个活动。 有没有办法存储列表项中每个条目的ID?我没有使用本地 SQLite 数据库或任何东西,所以我需要找到一种方法来“即时”执行此操作(如果可能) 提前致谢
I'm trying to build my first application which pretty much creates a list from an XML file on the net. as soon as i click on a list item it should open another activity and access another online generated XML file with the details for the item.
ive managed to get the list working aswell as the 2nd activity window with the details. the only thing thats left to do is to pass the id from one activity to another.
is there a way to store the ID of each entry in the list items? im not using a local SQLite db or anything, so i need to find a way to do this "on the fly" if possible
thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
谢谢我让它工作了!
这是代码,以防万一有人遇到同样的问题:
这是接收端:
thanks i got it to work!!
here is the code just in case someone has the same problem:
And here is the receiving end:
您的列表应该存在于数据模型上,一旦用户单击一行,您应该将该位置映射到模型中的一个点。如果您想将其组合在一起,可以使用 setTag() 在视图上存储任何类型的对象。这不是该函数的传统用法。如果您发布如何创建列表视图,它可能会更有帮助。
查看代码后,您可能想要执行以下操作:
查看传递额外内容 关于如何使用 putExtra()。
Your list should live on a model for data, and once a user clicks a row you should be mapping that location to a point in your model. If you want to just hack this together you can use setTag() on views to store any type of object. This is not a traditional use of this function. If you post how you are creating the the listview it might be more helpful.
After looking at your code you will probably want to do something like this:
Check out Passing Extras on how to use putExtra().