In protected void onListItemClick(ListView l, View v, int position, long id) method I use
lv.getChildAt(position-lv.getFirstVisiblePosition()).setBackgroundColor(getResources().getColor(android.R.color.darker_gray));
But background of two elements is changing ex. clicking first element (index 0) #0 and #8 change, clicking second item (index 1) #1 and #9 change, clicking 9th item (index 8) #8 and #1 change. What is going on?
----EDIT----
I used parameter v instead of lv.getChiledAt. It looks like that:
v.setBackgroundColor(getResources().getColor(android.R.color.darker_gray));
It still works the same way. I do not know where the problem is: listview, adapter, onlistitemclick method? I use the simplest adapter:
lv = (ListView) findViewById(android.R.id.list);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_2, android.R.id.text1, values);
lv.setAdapter(adapter);
lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
-----EDIT2---- Ok, one more thing. After clicking element i add its value to a list. And it works fine: to the list there is added only one element - however there are two positions highlighted. So the problem is somewhere with view... i can write my custom adapter, but it seems pretty complicated in this case. I would rather understand why this simple solution doesn't work.