Answer the question
In order to leave comments, you need to log in
How to set the color assigned to each gridview element in the sql database?
There is a list of #ffffff format colors stored in the sql database. I am displaying a list with color codes in a gridview, but I would like the background of each item in the list to match the color code from the list. How can i do this? I would be very happy with a piece of code, or at least a direction in which to look.
here is my most common adapter
db = new DBHelper(this);
db.open();
Cursor cursor = db.getColors();
startManagingCursor(cursor);
String[] cols = new String[]{DBHelper.COLORS_COLUMN_NAME};
int[] views = new int[]{R.id.tvText};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(ColorsActivity.this,
R.layout.grid_item,
cursor, cols, views);
gv = (GridView) findViewById(R.id.gvMain);
gv.setAdapter(adapter);
adjustGridView();
}
private void adjustGridView() {
gv.setNumColumns(GridView.AUTO_FIT);
gv.setVerticalSpacing(5);
gv.setHorizontalSpacing(5);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question