Hello. I am writing an application for work, which is a list of points with the ability to sort by day of the week, and by "mine are not mine" .. I redefined the SimpleCursorAdapter method to change the color of rows. But I would like to make this change depending on the My parameter or not, and not on the parity of the position .. The parameter "my" is stored in SQLite as "1" in the "isMy" column. I can not figure out how to get this value in the adapter ..

public class MyCursorAdapter extends SimpleCursorAdapter { public MyCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) { super(context, layout, c, from, to, flags); } @Override public View getView(int position, View convertView, ViewGroup parent) { View view = super.getView(position, convertView, parent); if (position % 2 == 0){ view.setBackgroundColor(Color.rgb(238, 233, 233)); } else { view.setBackgroundColor(Color.rgb(255, 255, 255)); } return view; } 

    3 answers 3

    You need to work not with getView () , but with bindBiew () and newView () they have in Cursor arguments, from where you can extract the value of your field.

       if (getCursor().getInt(getCursor().getColumnIndex("isMy")) == 1){ //столбец isMy = 1 } else { //столбец isMy = 0 } 

        Thanks for answers! In bindView

        if (cursor.getString(cursor.getColumnIndex("ismy")).equals("1")){ }else{ }

        and everything works fine. Only in the else condition must be necessary, and then there will be shoals))