K
K
Kitoved2017-06-12 19:39:03
Android
Kitoved, 2017-06-12 19:39:03

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

1 answer(s)
A
aol-nnov, 2017-06-12
@Kitoved

drank your adapter, inside it change the properties of the view in accordance with the incoming data.
search words, e.g. "android custom gridview adapter example"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question