mardi 27 octobre 2015

If statement for ViewHolder is returning false all everytime

back with yet another android question and feel as if I am missing something simple here.

The viewholder gets the content in the specific field of the table from which the result is read.

Now I would like to compare that result to a char to change the color of the layout it is in but unfortunately is not working as planned.

Here is the code for the holder:

@Override
public void bindView(View view, Context context, Cursor cursor) {
    super.bindView(view, context, cursor);
    ViewHolder holder = (ViewHolder) view.getTag();
    if (holder == null) {
        holder = new ViewHolder();
        holder.colImp = cursor.getColumnIndexOrThrow(BetDbAdapter.COL_OUTCOME);
        holder.listTab = view.findViewById(R.id.won_lost);
        view.setTag(holder);
    }
    if (cursor.getString(holder.colImp).trim() == "W" || cursor.getString(holder.colImp).trim() == "w") {
        holder.listTab.setBackgroundColor(context.getResources().getColor(R.color.green));
    } else {
        holder.listTab.setBackgroundColor(context.getResources().getColor(R.color.red));
    }
}

The if statement just keeps returning the red even though the content is a "W", here is a screen of the app:

screen

Also this is the insert, it is hardcoded at the moment for testing purposes:

mDbAdapter.createBet("W", 12.34, 14.78);
mDbAdapter.createBet("W", 23.77, 1.90);
mDbAdapter.createBet("W", 123.45, 134);
mDbAdapter.createBet("W", 0.4, 1.34);

Please see if you can see what I cannot to fix this.

Aucun commentaire:

Enregistrer un commentaire