Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9184485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:03:52+00:00 2026-06-17T19:03:52+00:00

code fragment of what I’ve tried: String servng, mealname, strDate; public void onClick(View v)

  • 0

code fragment of what I’ve tried:

    String servng, mealname, strDate;

public void onClick(View v) {
    // TODO Auto-generated method stub
    switch(v.getId()){
    case R.id.btFoodVegetableSave:
        mealname = selected;
        String serving  = calories.getText().toString();
        int i = Integer.parseInt(serving.replaceAll("[\\D]", ""));

        servng = String.valueOf(i);

        SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy");
        strDate = sdf.format(new Date());

        if ( ( mealname.isEmpty() || servng.isEmpty() ) ){

            // call for custom toast
            viewErrorToast();
        }

        else {

        boolean didItWork = true;

        try{

            rgMeal.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

                public void onCheckedChanged(RadioGroup group, int checkedId) {
                    // TODO Auto-generated method stub
                    switch( checkedId ){
                    case R.id.rbBreakfast:
                        BreakFastLog bfLog = new BreakFastLog(Bread_Dark.this);
                        bfLog.open();
                        bfLog.createEntry(mealname, servng, strDate);
                        bfLog.close();
                        break;
                    case R.id.rbMorningSnack:
                        MorningSnackLog msLog = new MorningSnackLog(Bread_Dark.this);
                        msLog.open();
                        msLog.createEntry(mealname, servng, strDate);
                        msLog.close();
                        break;
                    case R.id.rbLunch:
                        LunchLog lunchLog = new LunchLog(Bread_Dark.this);
                        lunchLog.open();
                        lunchLog.createEntry(mealname, servng, strDate);
                        lunchLog.close();
                        break;
                    case R.id.rbAfternoonSnack:
                        AfternoonSnackLog asLog = new AfternoonSnackLog(Bread_Dark.this);
                        asLog.open();
                        asLog.createEntry(mealname, servng, strDate);
                        asLog.close();
                        break;
                    case R.id.rbDinner:
                        DinnerLog dinnerLog = new DinnerLog(Bread_Dark.this);
                        dinnerLog.open();
                        dinnerLog.createEntry(mealname, servng, strDate);
                        dinnerLog.close();
                        break;
                    case R.id.rbEveningSnack:
                        EveningSnackLog esLog = new EveningSnackLog(Bread_Dark.this);
                        esLog.open();
                        esLog.createEntry(mealname, servng, strDate);
                        esLog.close();
                        break;
                    }
                }
            });


            }
            catch(Exception e){
                didItWork = false;
                viewErrorToast();
            }finally{
                if (didItWork){
                    viewBMRSavedToast();
                }

            }
        } // end of if else statement
        break;

the xml layout:

<LinearLayout
android:layout_width="match_parent"
android:layout_height="481dp"
android:background="@drawable/ihealthfirst"
android:orientation="vertical" >

<include
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    layout="@layout/tabs_menu" />

<TextView
    android:id="@+id/tvFoodVegetable"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/cabbage"
    android:layout_marginLeft="15dp"
    android:layout_marginTop="10dp"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

<EditText
    android:id="@+id/etAmount"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:text="@string/one"
    android:inputType="number" >


    <requestFocus android:layout_height="wrap_content" />

</EditText>

<Spinner
    android:id="@+id/spFoodVegetable"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:prompt="@string/white_bread_prompt" />


</LinearLayout>

<Button
    android:id="@+id/btFoodVegetableCalories"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/done"
    android:layout_margin="15dp"
    android:textColor="@color/darkgreen"
    android:textSize="@dimen/padding_extralarge"
    android:background="@drawable/btn_meal_selected" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="15dp"
    android:text="@string/choosemeal"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<RadioGroup
          android:paddingLeft="10dp"
          android:id="@+id/rgSelectMeal"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:orientation="vertical" >



<RadioButton
    android:id="@+id/rbBreakfast"
    android:layout_width="128dp"
    android:layout_height="wrap_content"
    android:text="@string/breakfast"
    android:checked="true" />

<RadioButton
    android:id="@+id/rbMorningSnack"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/morningsnack" />


   <RadioButton
       android:id="@+id/rbLunch"
       android:layout_width="128dp"
       android:layout_height="wrap_content"
       android:text="@string/lunch" />

<RadioButton
    android:id="@+id/rbAfternoonSnack"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/afternoonsnack" />

<RadioButton
    android:id="@+id/rbDinner"
    android:layout_width="127dp"
    android:layout_height="wrap_content"
    android:text="@string/dinner" />

<RadioButton
    android:id="@+id/rbEveningSnack"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/eveningsnack" />


</RadioGroup>

<Button
    android:id="@+id/btFoodVegetableSave"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/save"
    android:drawableLeft="@drawable/save24"
    android:background="@drawable/nutrition_button_gradiant"
    android:textColor="@color/white"
    android:layout_gravity="center"
    android:layout_marginBottom="15dp" />

</LinearLayout>

When the user would check from radio group and click the save button, it goes to my FINALLY statement:

 finally{
            if (didItWork){
                viewBMRSavedToast();
            }

But when i would check the summary (list of records inserted/saved to the database), it’s not being saved 🙁 what’s wrong with my handling of radiogroup here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T19:03:53+00:00Added an answer on June 17, 2026 at 7:03 pm

    If I understand you correctly you want the user to click on a radio button and then to create a new BreakFastLog when the user presses “Save”. What you’re currently doing is making a checkChangedListener for the radiogroup after the “Save” button has been clicked. This will cause the chain of events to happen in inverse order from what you want (what you’re seeing). In order for the user to select a radiobutton and then click “save” you only need to retrieve the currently checked radiobutton within the radiogroup, not make a checkChangedListener. This can be done by:

       int checkedId = rgMeal.getCheckedRadioButtonId()
       switch( checkedId ){
          case R.id.rbBreakfast:
              BreakFastLog bfLog = new BreakFastLog(Bread_Dark.this);
              bfLog.open();
              bfLog.createEntry(mealname, servng, strDate);
              bfLog.close();
              break;
          case R.id.rbMorningSnack:
              MorningSnackLog msLog = new MorningSnackLog(Bread_Dark.this);
              msLog.open();
              msLog.createEntry(mealname, servng, strDate);
                       .
                       .
                       .
                       .
         }
    

    `

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code fragment: public static class ExportDatabaseFileTask extends AsyncTask<String, Void, Boolean> {
This is a code fragment from my controller [HttpPost] public ActionResult Cancel(string id,FormCollection collection)
I have the following code fragment from a project I'm working on: public void
Is this code fragment OK or does it result in undefined behavior? std::string s;
in this C-code fragment: void func(void) { int x=10; if (x>2) { int y=2;
Below is my code fragment: <div onclick = myClick('value 1')> button 1 </div> <div
Why does this code fragment: if (iErr) { std::stringstream ss; string serror(error); ss <<
In this code fragment, I can't sum a and b : String a =
Please pardon the beginner question.I met this code fragment on the internet: public class
I have this code fragment class bst { public node root=null; bst() { root=null;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.