ListView selection issue...Using onItemClick(AdapterView<?> parent, View view, ...)
Posted
by searchMaker
on Stack Overflow
See other posts from Stack Overflow
or by searchMaker
Published on 2010-04-01T04:00:04Z
Indexed on
2010/04/01
4:03 UTC
Read the original article
Hit count: 837
The problem I hope to resolve here is that when I click on one item in the ListView that item's background changes to light gray, but when I continue to scroll through the list every 4th item has the background changed to light gray even though those other items have not been clicked. How do I make only the item I clicked be effected by the click?
ListView lv = (ListView) findViewById(R.id.resultsList);
lv.setAdapter(new ArrayAdapter(this, R.layout.resultitem, (String[])labelList.toArray(new String[labelList.size()])));
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View view, int position, long id) {
TextView tv = (TextView)view.findViewById(R.id.result);
tv.setBackgroundColor(Color.LTGRAY);
tv.setTextColor(Color.BLACK);
© Stack Overflow or respective owner