roughike / SwipeSelector

A nicer-looking, more intuitive and highly customizable alternative for radio buttons and dropdowns for Android.
Apache License 2.0
1.09k stars 154 forks source link

Swipe items from SQLite ? #5

Closed hendynugraha87 closed 8 years ago

hendynugraha87 commented 8 years ago

i already implement your library into my project and it looks marvelous. but sorry for ask, is there any clue how to set of SwipeItem objects using SQLite ? thanks.

roughike commented 8 years ago

Thanks for the compliment! I'm glad you like it.

Sure your can use data from SQLite database. Just iterate through the Cursor that has your data. I haven't tested this but here's a general idea:

Cursor c = db.query(
    // get the relevant rows here
);

SwipeSelector swipeSelector = (SwipeSelector) findViewById(R.id.swipeSelector);

if (c != null && c.getCount() > 0) {
    SwipeItem[] swipeItems = new SwipeItem[c.getCount()];
    int i = 0;

    while (c.moveToNext()) {
        int value = c.getInt(c.getColumnIndex("col_value"));
        String title = c.getString(c.getColumnIndex("col_title"));
        String description = c.getString(c.getColumnIndex("col_description"));

        swipeItems[i] = new SwipeItem(value, title, description);
        i++;
    }

    swipeSelector.setItems(swipeItems);
    c.close();
}