private List<TableRow> getTableRows(Context context, Cursor cursor) {

        List<TableRow> rows = new ArrayList<>();
        TableRow header = new TableRow(context);
        cursor.moveToFirst();

        int paddingPx = context.getResources().getDimensionPixelSize(R.dimen.hsql_column_padding);

        for (int col = 0; col < cursor.getColumnCount(); col++) {
            TextView textView = new TextView(context);
            textView.setText(cursor.getColumnName(col));
            textView.setPadding(paddingPx, paddingPx / 2, paddingPx, paddingPx / 2);
            textView.setTypeface(Typeface.DEFAULT_BOLD);
            header.addView(textView);
        }

        rows.add(header);

        boolean alternate = true;

        if (cursor.getCount() == 0) {
            return rows;
        }

        do {
            TableRow row = new TableRow(context);
            for (int col = 0; col < cursor.getColumnCount(); col++) {
                TextView textView = new TextView(context);
                if (cursor.getType(col) == FIELD_TYPE_BLOB) {
                    //We don't need to display the contents of the blob
                    textView.setText(R.string.hsql_data_type_blob);
                } else {
                    textView.setText(cursor.getString(col));
                }
                textView.setPadding(paddingPx, paddingPx / 2, paddingPx, paddingPx / 2);
                int rowBgRes;
                if (alternate) {
                    rowBgRes = R.color.hsql_table_row_colour_alt;
                } else {
                    rowBgRes = R.color.hsql_table_row_colour_standard;
                }
                textView.setBackgroundColor(context.getResources().getColor(rowBgRes));
                row.addView(textView);
            }

            alternate = !alternate;
            rows.add(row);

        } while (cursor.moveToNext());

        cursor.close();
        return rows;
    }
private List < TableRow > getTableRows ( Context context , Cursor cursor ) { List < TableRow > rows = new ArrayList < > ( ) ; TableRow header = new TableRow ( context ) ; cursor . moveToFirst ( ) ; int paddingPx = context . getResources ( ) . getDimensionPixelSize ( R . dimen . hsql_column_padding ) ; for ( int col = 0 ; col < cursor . getColumnCount ( ) ; col ++ ) { TextView textView = new TextView ( context ) ; textView . setText ( cursor . getColumnName ( col ) ) ; textView . setPadding ( paddingPx , paddingPx / 2 , paddingPx , paddingPx / 2 ) ; textView . setTypeface ( Typeface . DEFAULT_BOLD ) ; header . addView ( textView ) ; } rows . add ( header ) ; boolean alternate = true ; if ( cursor . getCount ( ) == 0 ) { return rows ; } do { TableRow row = new TableRow ( context ) ; for ( int col = 0 ; col < cursor . getColumnCount ( ) ; col ++ ) { TextView textView = new TextView ( context ) ; if ( cursor . getType ( col ) == FIELD_TYPE_BLOB ) { textView . setText ( R . string . hsql_data_type_blob ) ; } else { textView . setText ( cursor . getString ( col ) ) ; } textView . setPadding ( paddingPx , paddingPx / 2 , paddingPx , paddingPx / 2 ) ; int rowBgRes ; if ( alternate ) { rowBgRes = R . color . hsql_table_row_colour_alt ; } else { rowBgRes = R . color . hsql_table_row_colour_standard ; } textView . setBackgroundColor ( context . getResources ( ) . getColor ( rowBgRes ) ) ; row . addView ( textView ) ; } alternate = ! alternate ; rows . add ( row ) ; } while ( cursor . moveToNext ( ) ) ; cursor . close ( ) ; return rows ; }
Derived from https://github.com/infinum/android_dbinspector/blob/master/dbinspector/src/main/java/im/dino/dbinspector/adapters/TablePageAdapter.java