Note that there are some explanatory texts on larger screens.

plurals
  1. POANDROID radiogroup not saving oncheckedchangeListener
    text
    copied!<p><strong>code fragment of what I've tried:</strong></p> <pre><code> 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; </code></pre> <p><strong>the xml layout:</strong></p> <pre><code>&lt;LinearLayout android:layout_width="match_parent" android:layout_height="481dp" android:background="@drawable/ihealthfirst" android:orientation="vertical" &gt; &lt;include android:layout_width="fill_parent" android:layout_height="match_parent" layout="@layout/tabs_menu" /&gt; &lt;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" /&gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" &gt; &lt;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" &gt; &lt;requestFocus android:layout_height="wrap_content" /&gt; &lt;/EditText&gt; &lt;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" /&gt; &lt;/LinearLayout&gt; &lt;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" /&gt; &lt;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" /&gt; &lt;RadioGroup android:paddingLeft="10dp" android:id="@+id/rgSelectMeal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" &gt; &lt;RadioButton android:id="@+id/rbBreakfast" android:layout_width="128dp" android:layout_height="wrap_content" android:text="@string/breakfast" android:checked="true" /&gt; &lt;RadioButton android:id="@+id/rbMorningSnack" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/morningsnack" /&gt; &lt;RadioButton android:id="@+id/rbLunch" android:layout_width="128dp" android:layout_height="wrap_content" android:text="@string/lunch" /&gt; &lt;RadioButton android:id="@+id/rbAfternoonSnack" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/afternoonsnack" /&gt; &lt;RadioButton android:id="@+id/rbDinner" android:layout_width="127dp" android:layout_height="wrap_content" android:text="@string/dinner" /&gt; &lt;RadioButton android:id="@+id/rbEveningSnack" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/eveningsnack" /&gt; &lt;/RadioGroup&gt; &lt;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" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>When the user would check from radio group and click the save button, it goes to my FINALLY statement:</p> <pre><code> finally{ if (didItWork){ viewBMRSavedToast(); } </code></pre> <p>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?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload