I have successfully used a SimpleCursorAdapter to list displayname and value (both in my DB) and displayed them in my list activity.
What I am was trying to do now was add a new view (ImageView) for each item in my list activity. It is supposed to look like this in the end.
Image_1_NotInDB -- DisplayName1FromDB -- DisplayName1FromDB
Image_2_NotInDB -- DisplayName2FromDB -- DisplayName2FromDB.
The image is going to different (based on DisplayName1FromDB). I don’t think SimpleCursorAdapter is good anymore for this purpose.
I tried creating a customSimpleCursorAdapter extending SimpleCursorAdapter and tried to use ‘newView’ and ‘bindView’ methods to achieve. I pretty much followed this: Custom CursorAdapters.
The problem is; what Image I use is based on a value from DB (which I intended to pass in the constructor or customSimpleCursorAdapter)
public View newView(Context pContext, Cursor pCursor, ViewGroup pParent)
{
Cursor lCursor = getCursor();
final LayoutInflater inflater = LayoutInflater.from(pContext);
View lView = inflater.inflate(layout, pParent, false);
int lImage = "dog".equals(variable) ? R.drawable.dog : R.drawable.cat;
// "variable" is a member variable (set at the constructor)
ImageView lImageView = (ImageView) lView.findViewById(R.id.appImage);
if (lImageView != null)
{
lImageView.setImageResource(lImage);
}
return pParent;
}
public void bindView(View pView, Context pContext, Cursor pCursor)
{
int lImage = "dog".equals(variable) ? R.drawable.dog : R.drawable.cat;
// "variable" is a member variable (set at the constructor)
ImageView lImageView = (ImageView) lView.findViewById(R.id.appImage);
if (lImageView != null)
{
lImageView.setImageResource(lImage);
}
}
This is how I tried using the “customSimpleCursorAdapter”
String[] lDisplay = new String[] {KEY_NAME, KEY_TIME};
int[] lValues = new int[] {R.id.name, R.id.time};
CustomRowCursorAdapter lCursorAdapter = new CustomRowCursorAdapter(this, R.layout.row, lSTime, lDisplay, lValues, "MY IDEA WAS TO PASS THE ANIMAL NAME HERE, BUT NOT LUCK as I am not sure How ");
lCursorAdapter.newView(this, lSTime, getListView());
lCursorAdapter.bindView(getListView(), this, lSTime);
setListAdapter(lCursorAdapter);
Is ArrayAdapter the answer? If yes, could you share what parameters would you pass to it?
I recommend to go for custom adapter