Change imageview for selected item in listview

user3799934

In my layout I have a button and a listview. How can I change the imageview of item I selected when the button is clicked. So lets say, I select 5 items, and after I click the button, images for those 5 items will be changed.

So I am confused what function I should use. Right now i used button.setOnClickListener but it seems wrong because only the very first item's imageview will be changed when button clicked. Should I use listview.setItemOnClickListener? Or is there any other way I can do this?

Thanks a lot!

Kevin Galligan

Add a boolean to the data object in your adapter. Say you've got ArrayAdapter<MyDataObject>. Add some kind of "selected" field in the MyDataObject, and toggle it when you "select" the row.

Override getView in the adapter (you'll need a custom Adapter, btw. I'd just extend ArrayAdapter). When you render the row, if the "selected" field is true, show the "other" image.

When you click the button, call 'notifyDataSetChanged' on the adapter. The will cause the visible rows to refresh themselves (and call getView for each).

I think that'll work.

Since you only want images to change when you click the button, you'll need to have some kind of global boolean, so the getView won't show the image until the button has been clicked.

The complication here is, you have to deal with rows that may have been scrolled out of view, which don't have active views, but logically exist. It would be really hard to explain the concept here. I'd suggest some tutorials on ListView if you're not familiar with the recycling of row views.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Listview change appearance for selected item

From Dev

Android listview change item selected state in adapter

From Dev

How to change the Foreground Color of ListView Selected Item

From Dev

How to change style of Selected ListView Item in UWP

From Dev

How to change the Foreground Color of ListView Selected Item

From Dev

How to change style of Selected ListView Item in UWP

From Dev

How to change selected listview item color

From Dev

How do I change the color of a selected item on a ListView?

From Dev

Android ListView. How to change background color of manually selected item

From Dev

Change background color and font color of selected item in listview

From Dev

How to change color of the selected ListView item [WP8.1]

From Dev

How to change Highlight color of the selected ListView item in UWP (Windows 10)

From Dev

how to change color of list item when it is selected in listview?

From Dev

How can I change automatically the selected item in a ListView?

From Dev

xamarin forms: Couldn't change the background color of selected item on ListView

From Dev

If one item is selected in listview

From Dev

Selected Listview item (arrow?)

From Dev

Check if ListView item selected

From Dev

Setting a ListView item to selected

From Dev

Selected Listview item (arrow?)

From Dev

One selected item on a listview

From Dev

Check if ListView item selected

From Dev

Change color of ListView Selected Item and also change different color to non selected Items

From Dev

set onClickLitener of ImageView of a item of ListView

From Dev

TreeView Selected Item Change

From Dev

change selected item in autocomplete

From Dev

Change image in imageview on click on a listview

From Dev

get selected item - ListView Android

From Dev

Set the selected item of a listview to nothing

Related Related

  1. 1

    Listview change appearance for selected item

  2. 2

    Android listview change item selected state in adapter

  3. 3

    How to change the Foreground Color of ListView Selected Item

  4. 4

    How to change style of Selected ListView Item in UWP

  5. 5

    How to change the Foreground Color of ListView Selected Item

  6. 6

    How to change style of Selected ListView Item in UWP

  7. 7

    How to change selected listview item color

  8. 8

    How do I change the color of a selected item on a ListView?

  9. 9

    Android ListView. How to change background color of manually selected item

  10. 10

    Change background color and font color of selected item in listview

  11. 11

    How to change color of the selected ListView item [WP8.1]

  12. 12

    How to change Highlight color of the selected ListView item in UWP (Windows 10)

  13. 13

    how to change color of list item when it is selected in listview?

  14. 14

    How can I change automatically the selected item in a ListView?

  15. 15

    xamarin forms: Couldn't change the background color of selected item on ListView

  16. 16

    If one item is selected in listview

  17. 17

    Selected Listview item (arrow?)

  18. 18

    Check if ListView item selected

  19. 19

    Setting a ListView item to selected

  20. 20

    Selected Listview item (arrow?)

  21. 21

    One selected item on a listview

  22. 22

    Check if ListView item selected

  23. 23

    Change color of ListView Selected Item and also change different color to non selected Items

  24. 24

    set onClickLitener of ImageView of a item of ListView

  25. 25

    TreeView Selected Item Change

  26. 26

    change selected item in autocomplete

  27. 27

    Change image in imageview on click on a listview

  28. 28

    get selected item - ListView Android

  29. 29

    Set the selected item of a listview to nothing

HotTag

Archive