I want to change the background color of newly added listview rows. My listview is based on a custom adapter and the layout is inflated using the layout xml. I have tried many solutions but its somehow not working. I am not able to get the row elements in the listview. Thanks.
-
1Are you using custom adapter? It is possible if you are using custom adapter only. – Sunil Kumar Sahoo Dec 28 '11 at 14:35
-
1Would you mind posting some sample code? – Chase Dec 28 '11 at 14:43
3 Answers
You can study more here
http://developer.android.com/reference/android/widget/BaseAdapter.html
In addition, you can search with key word "Custom adapter"
here is some;

- 1
- 1

- 1,810
- 2
- 28
- 52
-
what has that to do with getting new rows and changing their background color? I have no problems with adapters. – Sultan Saadat Dec 29 '11 at 04:57
If the goal of the implementation is to show a newly added items in the adapter in a different color then you could implement the following logic.
Custom adapter, which you already have. Another Arraylist to keep track of newly added items. Add any new items to this arraylist.
in the getView() method, check if this item from the adapter is present in this auxiliary array, if present, change the background color of the view that you would return.
After sometime, maybe a timer, you may want to remove those elements from the auxiliary item.
Memory consumption maynot be too high because you are only storing reference to the objects that are present in the adapter already and not making a new copy.

- 2,694
- 1
- 19
- 20
I believe if you are saving the data you show in the ListView in array or database, you have to save the size of the array in SharedPreferences after setting the listadapter. Now assume you have 5 elements in your ListView and you save that, when you add again you have 8 elements, 8-5=3 now you know that the last 3 elements are new and you override the SharedPreferences with 8 (and so on..), in your custom listadapter change the background of the last 3 elements since you have all the values and the position of the row in the function:
public View getView(int i, View convertView, ViewGroup parent)
Which is the Integer i.

- 5,358
- 7
- 37
- 57