0

I overwrite the behavior of a spinner, to add odd and even colors to the drop down list, in this way.

    SimpleCursorAdapter productsListAdapter = new SimpleCursorAdapter(MyActivity.this, R.layout.spinner_drop_down_products, cursor, column, viewIds) {
    @Override
    public View getDropDownView(int position, View convertView, ViewGroup parent) {
        View view = super.getDropDownView(position, convertView, parent);
        if (position % 2 == 0) { 
            view.setBackgroundColor(android.graphics.Color.rgb(255, 255, 255));
        } else {
            view.setBackgroundColor(android.graphics.Color.rgb(214, 214, 214));
        }
        return view;
    }
};

The dropdown rows look as i expected ... but i loose the highlight on pressing each row. What i forget to add to the code? Thanks

Shruti
  • 1
  • 13
  • 55
  • 95
tinti
  • 1,455
  • 8
  • 23
  • 39

1 Answers1

0

Actually android framework uses selectors for all states like:

  1. normal enabled
  2. pressed
  3. highlight
  4. focused

The default selector for list is list_selector_background.xml You can see here.

You have to provide this by yourself. Say you have made a you_own_selector.xml then you will give this as a background of your View like this:

view.setBackgroundColor(R.drawable.you_own_selector);

Here is another nice post about using selectors in android.

Community
  • 1
  • 1
Adil Soomro
  • 37,609
  • 9
  • 103
  • 153