简体   繁体   English

使用SimpleCursorAdapter在Android ListActivity中访问视图的行

[英]Accessing the view for a row in an Android ListActivity with a SimpleCursorAdapter

I have a ListActivity that's populated with a SimpleCursorAdapter which pulls the data from a database. 我有一个用SimpleCursorAdapter填充的ListActivity,它从数据库中提取数据。 I want to set images on the rows at runtime based on the data in the database. 我想在运行时根据数据库中的数据在行上设置图像。 If the data is a one, I want a filled-in icon, and if it is 0, I want it to be hollow. 如果数据是一个,我想要一个填充的图标,如果它是0,则希望它是空心的。

In order to do this, I figured it would be easiest to access the layout of each row individually, and change the image, but I can't figure out how to access the individual rows without clicking on them. 为了做到这一点,我认为最简单的方法是分别访问每一行的布局并更改图像,但是我无法弄清楚如何在不单击各行的情况下访问它们。

I also eventually want the image itself to have a separate click event from the row it's on, but I'll probably ask another question for that. 我最终还希望图像本身与其所在的行有一个单独的click事件,但是我可能会问另一个问题。

While 100rabh's link did help me construct better searches which helped me answer the question, the answer I needed was that I needed to build my own custom cursorAdapter which I just extended from SimpleCursorAdapter. 虽然100rabh的链接确实帮助我构建了更好的搜索,从而帮助我回答了该问题,但我需要的答案是,我需要构建自己的自定义cursorAdapter,而我只是从SimpleCursorAdapter扩展而来的。

The setViewImage(ImageView v, String value) method helped, although I also did a bit of customization on bindImage to handle all of my cases for the various lists I used this for. 尽管我还对bindImage进行了一些自定义,以处理我为此使用的各种列表的所有情况,但setViewImage(ImageView v,String value)方法有所帮助。

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

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