TouchBoarder / weekdays-buttons-bar

"Weekdays Buttons Bar" is an Android library that makes it easy to integrate weekdays selection in your layout.
MIT License
146 stars 25 forks source link

setSelectedDays(int... days) with list values? #9

Open vipulasri opened 7 years ago

vipulasri commented 7 years ago

how can i dynamically set values in setSelectedDays(int... days) by getting ids stored in list?

TouchBoarder commented 7 years ago

weekdaysDataSource..setSelectedDays(int[2,3,4])//Use an array with Calendar class constants like Calendar.MONDAY

Check out the sample code for how to implement W-B-B in various ways https://github.com/TouchBoarder/weekdays-buttons-bar/blob/master/sample/src/main/java/com/touchboarder/weekdaysdemo/MainActivity.java

vipulasri commented 7 years ago

I am doing the same thing, but the selected weekdays are different:

if(child.getTimings()!=null && child.getTimings().size()>0){

        int[] ret = new int[child.getTimings().size()];
        for (int i=0; i < ret.length; i++) {
            switch (child.getTimings().get(i).getWeekday()) {
                case "Sunday":
                    ret[i] = Calendar.SUNDAY;
                    break;
                case "Monday":
                    ret[i] = Calendar.MONDAY;
                    break;
                case "Tuesday":
                    ret[i] = Calendar.TUESDAY;
                    break;
                case "Wednesday":
                    ret[i] = Calendar.WEDNESDAY;
                    break;
                case "Thursday":
                    ret[i] = Calendar.THURSDAY;
                    break;
                case "Friday":
                    ret[i] = Calendar.FRIDAY;
                    break;
                case "Saturday":
                    ret[i] = Calendar.SATURDAY;
                    break;
            }
        }

        Log.e("timings","->"+ Arrays.toString(ret));
        mWeekdaysDataSource.setSelectedDays(ret);
TouchBoarder commented 7 years ago

Please take a look at how this is implemented in the source code: getDays() https://github.com/TouchBoarder/weekdays-buttons-bar/blob/master/module/src/main/java/com/touchboarder/weekdaysbuttons/WeekdaysDataSource.java