mystic cola
mystic cola

Reputation: 1643

Android Save RadioGroup Opening Hours Temporarily

I've looked and looked but haven't found anything like I'm trying to do on here. I'm trying to create an input for opening hours using the 7 days of the week and an opening and closing time. The fastest way I could get this going, visually at least, was to create a RadioGroup with Radio Buttons for Monday thru Sunday then corresponding Opening and Closing times.

Opening Hours

The problem with using Radio Buttons to do this, of course, is you only select one at a time. So I'm wondering if there's a way I can store the "From" and "Until" inputs for each one of the days of the week until I have all 7 and then send all seven at once? (I'd also like for the correct time to be displayed if you were to switch, for example, from Saturday (which is open from 9am) to Monday (which is open from 10am) it shows the time that you set it to.

Here's how I currently have the buttons setup:

radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

    @SuppressLint("SuspiciousIndentation")
    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        int id=group.getCheckedRadioButtonId();
        RadioButton rb=(RadioButton) findViewById(id);

      radioText=rb.getText().toString();
        Log.d(TAG, "Radio nfo: " + radioText);
        


    }
});

That gets the day of the week.

protected Map<String, String> getParams() {
               Map<String, String> params = new HashMap<String, String>();
                params.put("mon", fromtime + " to " + untiltime);
                params.put("tue", fromtime + " to " + untiltime);
                params.put("wed", fromtime + " to " + untiltime);
                params.put("thu", fromtime + " to " + untiltime);
                params.put("fri", fromtime + " to " + untiltime);
                params.put("sat", fromtime + " to " + untiltime);
                params.put("sun", fromtime + " to " + untiltime);
                return params
                }

And that's how they ultimately get sent to the database. But the ideal would be to replace mon-sun with something like "radioText1" thru "radiotext" 7. And, currently, fromtime and untiltime are simple editText fields. It would be nice to have them associated with each one of the radio button options somehow.

Speaking of which... here's how they're setup in the layout currently:

<RadioGroup
            android:id="@+id/venue_days"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <RadioButton
                android:id="@+id/radioMon"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Mo"
                />

            <RadioButton
                android:id="@+id/radioTue"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Tu"
                />

            <RadioButton
                android:id="@+id/radioWed"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="We" />

            <RadioButton
                android:id="@+id/radioThu"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Th" />

            <RadioButton
                android:id="@+id/radioFri"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Fr" />

            <RadioButton
                android:id="@+id/radioSat"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Sa" />

            <RadioButton
                android:id="@+id/radioSun"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Su" />

        </RadioGroup>

Again... the idea is to select a RadioButton... input the from and until data... somehow have that and then move on to the next one until you have all of them, then map them each and send them to the correct day of the week.

I know something like a Checkbox system would probably be much more effective for opening hours... but I'm still curious if there IS a way to save data while switching Radio Buttons... or if such a thing is simply impossible and you can only select the text attached to each button. (If so... then I'd gladly accept a CheckBox solution instead.)

Upvotes: 0

Views: 14

Answers (0)

Related Questions