title: Strange behaviour in Expandablelistview - Android
body: <p>Im trying to implement an activity that uses ExpandableListView and I have gotten so far but now I have found some strange behavior.</p>
  
  <p>My activity is meant to record food intake as specified by the user. they have a choice of menus (breakfast, lunch and dinner - the outer group) which expand to show their contents.
  when a user clicks on an inner menu item a dialog appears asking them for the qty. once they enter a qty and dismiss the dialog the text on the menu item changes to reflect the quantity of that item that has  been consumed
  <img src="https://i.stack.imgur.com/BWxmm.jpg" alt="fig 1"></p>
  
  <p>The above image shows the list in a closed state.</p>
  
  <p>below is the list after I have opened the lunch menu and clicked on 'Potato Chips' and indicating a Quantity of 1. As you can see the 'Potato' itemtext has now been changed to reflect the Qty of 1.</p>
  
  <p><img src="https://i.stack.imgur.com/Nyi6p.jpg" alt="fig 2"></p>
  
  <p>The strange part happens now. if I click on 'Lunch' and close the list and then click on it again re-opening it, the 'Qty X 1' text has jumped to another item (Milk)</p>
  
  <p><img src="https://i.stack.imgur.com/MopI2.jpg" alt="alt text"></p>
  
  <p>each time I open and close the list it jumps back and forth between the two items. Also if I open up other items, such as breakfast, I find that they too have now gotten items with 'Qty X 1' even though I havent clicked them.</p>
  
  <p>The bits of code that are relevant are as such:</p>
  
  <p>The XML for a child element:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="horizontal"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"&gt;
  
      &lt;TextView android:id="@+id/childname"
           android:paddingLeft="50dip"
  
           android:textSize="14dip"
           android:textStyle="italic"
           android:layout_width="200dip"
           android:textColor="@color/black"
           android:layout_height="40dip"/&gt;
  
      &lt;TextView android:id="@+id/qty_display"
           android:text="-"
           android:textSize="14dip"
           android:textStyle="italic"
           android:layout_width="50dip"
           android:textColor="@color/black"
           android:layout_height="wrap_content"/&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>The code thats triggered on clicking a child element:</p>
  
  <pre><code>public boolean onChildClick(
              ExpandableListView parent, 
              View v, 
              int groupPosition,
              int childPosition,
              long id) {
  
             // open the dialog and inflate the buttons
       myDialog  = new Dialog(this);
    myDialog.setTitle("Food Item Qty");
    myDialog.setContentView(R.layout.food_intake_dialog);
    final Button ok = (Button)myDialog.findViewById(R.id.fi_ok_but);
       Button cancel = (Button)myDialog.findViewById(R.id.fi_cancel_but); 
  
       //the id for this item is stored as a hash key in a map (say, item_id01)
       String key = "item_id"+groupPosition+""+childPosition;
       current_selected_food_item_id = Integer.parseInt(itemMap.get(key));
  
         // inflate the textview that shows the qty for this item on the expandablelist
       barQty = (TextView) v.findViewById(R.id.qty_display);
  
          // set the ok button to record teh quantity on press
       ok.setOnClickListener(new OnClickListener() {
     public void onClick(View viewParam) {
  
                               //inflate the input box that receives quantity from user
      EditText fiQty = (EditText) myDialog.findViewById(R.id.fiQty);
      // get the quantity and append the text on hte list item
      String qty = fiQty.getText().toString();
      barQty.setText("Qty X "+qty);
  
                              //open the database and save state 
                  FoodIntake.this.application.getFoodIntakeHelper().open();   
   FoodIntake.this.application.getFoodIntakeHelper().storeFoodIntakeLog(current_selected_food_item_id,qty,visit_id,remote_visit_id);
      String log = FoodIntake.this.application.getFoodIntakeHelper().getFoodIntakeLog(visit_id);
      FoodIntake.this.application.getFoodIntakeHelper().close();
  
                          //    append the main food intake list and close the dialog
                              list.setText("Food Intake Log:\n\n"+log);
      myDialog.cancel();
     }
       });
  </code></pre>
  
  <p>The above code opens a dialog, accepts a value for quantity, appends the list element to reflect this, also saves to database and sets a textview with the selected item and quantity.</p>
  
  <p>Sorry to just dump a whole load of code, but this has me stumped and hopefully someone can help.</p>
  
  <p>Thanks</p>
  
  <p>Kevin</p>