I have an app with a ListView with custom items in a ListFragment. Purpose of the app is a checklist with tasks that change background color and add a checkmark when they're selected.
Now when the task is selected it passes this info to the connected SQLite-db and reloads the adapter. With an if-statement it checks if the task is finished and if so it adds a checkmark and changes the background. This all worked fine, but when I have more tasks than the screen can hold it jumps to the top when reloading the adapter, standard behavior.
I've been experimenting with the info found on this page: Android: Is it possible to refresh just one item in a listview? And this info has been pretty helpful:
View v = listViewItems.getChildAt(position -
listViewItems.getFirstVisiblePosition());
v.setBackgroundColor(Color.GREEN);
My own implementation is this:
private void updateView(int index){
View v = getListView().getChildAt(index -
getListView().getFirstVisiblePosition());
if(v == null)
return;
v.setBackgroundColor(getResources().getColor(R.color.finished_bg));
IconTextView itv = (IconTextView) v.findViewById(R.id.task_item_icontextview);
itv.setVisibility(View.VISIBLE);
}
Here is where it gets tricky.
1: It changes background, really nice, but when I scroll up or down and the item leaves the screen and then re-enters the background is back to it's standard color. How do I make sure that the color stays this way?
2: The checkmark doesn't show at all. Am I making wrong references? Is it even possible to change properties this way?