This code will output the colour string ouf the clicked row or nothing if there is no colour background set. But you didn't specify how exactly you set the background colour.
ListView listView = (ListView) findViewById(R.id.listView);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);
adapter.add("Blue");
adapter.add("None");
adapter.add("Red");
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
int color;
Drawable background = view.getBackground();
if (background instanceof ColorDrawable) {
color = ((ColorDrawable) background).getColor();
Log.d("MainActivity", Integer.toHexString(color));
}
}
});
listView.setAdapter(adapter);
findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listView.getChildAt(0).setBackgroundColor(ContextCompat.getColor(MainActivity.this, android.R.color.holo_blue_dark));
listView.getChildAt(2).setBackgroundColor(ContextCompat.getColor(MainActivity.this, android.R.color.holo_red_dark));
}
});