I have a listview which is populated with locations, When you click on a location this brings up jobs to be done within this location. When all jobs have been completed you then click on a ok button now at this point I want the selected location row in the listview background colour to change. What I have so far for the button
mOkBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
View listView = getActivity().findViewById(R.id.area_list);
listView.setBackgroundColor(Color.GREEN);
mArea.checkResult = CheckResult.OK;
mArea.checkTimeStamp = System.currentTimeMillis()/1000L;
showResults();
}
});
At the moment this changes the whole listview green, but im not sure how to get it to change just the selected row.
thx
For setting the colour, you need a selector. You can set this on your list using the android:listSelector attribute as :
And list_selector.xml :
You can set the background color of listview as follows,
If your listview shows black when you scrolling the listview then add the some code in xml as
I think it may helpful to you.