0

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.

Sultan Saadat
  • 2,268
  • 6
  • 28
  • 38

3 Answers3

0

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;

custom adapter for gridview in android

Community
  • 1
  • 1
April Smith
  • 1,810
  • 2
  • 28
  • 52
0

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.

Prakash Nadar
  • 2,694
  • 1
  • 19
  • 20
0

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.

Hesham Saeed
  • 5,358
  • 7
  • 37
  • 57