@Override public void bindView(View view,Context context, Cursor cursor) { String name = cursor.getString(cursor.getColumnIndex(DBHelper.COLUMN_1)); String time = cursor.getString(cursor.getColumnIndex(key)); if(cursor.getPosition() % 2 == 0){ ((TextView)view.findViewById(R.id.textView)).setText(name); ((TextView)view.findViewById(R.id.textView2)).setText(time); } else { ((TextView)view.findViewById(R.id.textView3)).setText(name); ((TextView)view.findViewById(R.id.textView4)).setText(time); } } @Override public View newView(Context context, Cursor cursor, ViewGroup parent) { View view; LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE); if(cursor.getPosition() % 2 == 0) { // Чтобы менять попеременно цвет в ListView view = inflater.inflate(R.layout.item_1, parent, false); } else { view = inflater.inflate(R.layout.item_2, parent, false); } return view; } 

This is my class inherited from SimpleCursorAdapter. I fill in a database in listview. I want to make the colors of an individual listview change alternately. But the cursor during a sharp rewind down or up comes off the sum and it is impossible to track the next view like mine using the cursor position. How can this be implemented? I repeat, I need that in the SimpleCursorAdapter, the colors of the individual view-elements change alternately in two colors.

  • one
    Type in the search for this site: getItemViewType, many times already answered this question. - pavlofff
  • Switch to RecyclerView , much more convenient - Flippy

0