How can I update a single row in a ListView?

前端 未结 11 2073
时光说笑
时光说笑 2020-11-22 17:07

I have a ListView which displays news items. They contain an image, a title and some text. The image is loaded in a separate thread (with a queue and all) and w

11条回答
  •  情话喂你
    2020-11-22 17:23

    This question has been asked at the Google I/O 2010, you can watch it here:

    The world of ListView, time 52:30

    Basically what Romain Guy explains is to call getChildAt(int) on the ListView to get the view and (I think) call getFirstVisiblePosition() to find out the correlation between position and index.

    Romain also points to the project called Shelves as an example, I think he might mean the method ShelvesActivity.updateBookCovers(), but I can't find the call of getFirstVisiblePosition().

    AWESOME UPDATES COMING:

    The RecyclerView will fix this in the near future. As pointed out on http://www.grokkingandroid.com/first-glance-androids-recyclerview/, you will be able to call methods to exactly specify the change, such as:

    void notifyItemInserted(int position)
    void notifyItemRemoved(int position)
    void notifyItemChanged(int position)
    

    Also, everyone will want to use the new views based on RecyclerView because they will be rewarded with nicely-looking animations! The future looks awesome! :-)

提交回复
热议问题