I'm using SimpleCursorAdapter to retrieve data from a SQLite database and using a custom layout and a listview to display two strings from the database. Now I have two questions:
Do I have to create a custom adapter if I want to display a star in specific rows based on a specific criteria? I have the image already set to invisible in my custom layout and want to set it to visible based on some conditions on the row data itself. I implemented all the tabs as well as the favorites tab and all works properly, I just needed the star icon. I face this problem also with putting the recipe image to a specific rows.
What is the best way to get images dynamically in listviews? I've followed the lazy image tutorial, but I didn't know how to implement it using the CustomCursorAdapter because it was implemented using the baseadapter. What are some links to a lazyloading images with simplecursor tutorials?
public class AlternateRowCursorAdapter extends SimpleCursorAdapter{
int layoutn;
Cursor mCursor;
String[] fromn;
int[] ton;
LayoutInflater mInflater;
private int[] colors = new int[] { Color.parseColor("#000000"), Color.parseColor("#303030") };
public AlternateRowCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
super(context, R.layout.listtype, c, from, to);
this.mCursor = c;
}
/**
* Display rows in alternating colors
*/
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
ImageView star = (ImageView)view.findViewById(R.id.favoritesicon); // The star I want to show
if (mCursor.getString(8) == "YES") // shows if the item is in favorites
{
star.setVisibility(view.VISIBLE);
}
int colorPos = position % colors.length;
view.setBackgroundColor(colors[colorPos]);
return view;
}
}