Я хотел иметь возможность отображать строки моего списка в разных цветах в зависимости от их типа.Поэтому я создал собственный адаптер с помощью приведенного ниже кода.
startManagingCursor(cursor);
Lectures_Adapter adapter = new Lectures_Adapter(this,R.layout.menu_item,cursor,FROM,TO);
menuList.setAdapter(adapter);
пользовательский адаптер использует этот код -
public Lectures_Adapter(Context context, int layout, Cursor c, String[] from,int[] to) {
super(context, layout, c, from, to);
this.appContext=context;
this.layout=layout;
this.mycursor=c;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
if (position > 0)
{
RelativeLayout rowFill = (RelativeLayout) convertView.findViewById(R.id.rowFill);
String title = mycursor.getString(0);
int myColor = 0;
int myPos = title.indexOf("Nurse");
int myPos2 = title.indexOf("masterclass");
if (myPos >= 0)
{
myColor = Color.parseColor("#99FF66");
}
else if (myPos2 >= 0)
{
myColor = Color.parseColor("#FF99FF");
}
else
{
myColor = Color.parseColor("#FFFF66");
}
convertView.findViewById(R.id.rowFill).setBackgroundColor(myColor);
}
return view;
}
Все работает нормально и отображает строки в соответствующих цветах, ноПервая страница всегда остается неизменной (за исключением первой строки), и когда я выбираю строку и возвращаюсь к списку, изменения не применяются.Как я могу заставить Listview постоянно сохранять настройки пользовательских адаптеров?