I have successfully used SimpleCursorAdapter to display the display name and value (both in my database) and display them in my list activity.
What I'm trying to do now is add a new view (ImageView) for each item in my list. In the end, it should look like this.
Image_1_NotInDB -- DisplayName1FromDB -- DisplayName1FromDB
Image_2_NotInDB -- DisplayName2FromDB -- DisplayName2FromDB.
Image will be different (based on DisplayName1FromDB). I do not think SimpleCursorAdapter is good for this purpose.
I tried to create a customSimpleCursorAdapter that extends SimpleCursorAdapter, and tried to use the 'newView' and 'bindView' methods to achieve. I pretty much followed this up: Custom CursorAdapters .
The problem is this: which image am I using based on the value from the database (which I was going 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;
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;
ImageView lImageView = (ImageView) lView.findViewById(R.id.appImage);
if (lImageView != null)
{
lImageView.setImageResource(lImage);
}
}
This is how I tried using "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 the ArrayAdapter the answer? If so, could you share what parameters you could pass to him?