如何附加一些“元数据” Android 列表视图项目?
class Venue {
private int id;
private String name;
}
我用类似的内容填充 ListView
List<String> venueNames = data.getVenueNames();
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, venueNames));
,因此在用户选择特定列表项后,我想使用场地 id 进行 SQLite 查询,但在创建场地名称时此信息会丢失。你们怎么解决这个问题?
编辑:我应该提到的是,不能保证场地名称是唯一的。
class Venue {
private int id;
private String name;
}
I populate the ListView with something like
List<String> venueNames = data.getVenueNames();
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, venueNames));
So after the user selects a particular list item, I'd like to do a SQLite query with the venue id, but this information is lost when creating the venue names. How do you guys solve this?
EDIT: I should mention that it isn't guaranteed that venue name is unique.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的问题就在这里:
不要这样做。您是“丢失”信息的人。如果你不想失去它,就不要失去它。
最简单的事情是创建一个
ArrayAdapter
,并让Venue
的toString()
返回name
。然后,在ArrayAdapter
上调用getItem()
将返回一个Venue
。Your problem is here:
Don't do that. You are the one "losing" the information. If you don't want to lose it, don't lose it.
The simplest thing is to create an
ArrayAdapter<Venue>
, and haveVenue
'stoString()
returnname
. Then, callinggetItem()
on yourArrayAdapter<Venue>
will return aVenue
.