-1

I have a question. I have an array of objects which I've added into an ArrayAdapter and the adapter in a listview. My listView is coloured in a color on odd positions and on even in another color. Now comes the tricky part. My object is composed of Strings id and name, String comments and a date. Can I colour the entries that have the id/name preset? For example, If i login and I want to see the listview, the entries where I appear (I already preserved the id with shared preferences) are coloured in another color than the other. From 5 entries, lets say, I appear in 3 of them, at random position. How to color the positions where I appear?

Thank you!

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Tayfun Omer
  • 172
  • 1
  • 1
  • 7

1 Answers1

1

I did something very similar. I wanted to change the font color instead of the whole item but you can replace my code with yours.

@Override
public View getView(int position, View v, ViewGroup parent)
{
    View mView = v ;
    if(mView == null){
        LayoutInflater vi = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mView = vi.inflate(id, null);
    }

    TextView text = (TextView) mView.findViewById(R.id.textView);

    if(items.get(position) != null ) //here you can match IDs and change the accordingly 
    {
        text.setTextColor(Color.WHITE);
        text.setText(items.get(position));
        text.setBackgroundColor(Color.RED); 
        int color = Color.argb( 200, 255, 64, 64 );
            text.setBackgroundColor( color );

    }

    return mView;
}
3iL
  • 2,146
  • 2
  • 23
  • 47