Strange behavior in Expandablelistview - Android

I am trying to implement an action that uses an ExpandableListView, and I got it so far, but now I have found strange behavior.

My activity is to record meals as indicated by the user. they have a choice of menus (breakfast, lunch and dinner - an outside group) that expand to show their contents. when a user clicks on an internal menu item, a dialog box appears asking for the quantity. as soon as they enter a number and reject the dialog, the text in the menu item changes to reflect the amount of this item that has been used up fig 1

The above image displays the list in a closed state.

, " " 1. , "" , 1.

fig 2

. "" , , , "Qty X 1" ( "" )

alt text

, , . , , , , "Qty X 1", .

:

XML :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <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"/>

    <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"/>
</LinearLayout>

, :

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();
   }
     });

, , , , .

, , , , - .

+3
3

, . , . , ExpandableListView . , , . , , .

-1

Android. , , , . , , onPrepareDialog() .

+1

Here is a solution that helped solve my ExpandableListView weird behavior problem. Our custom ExpandableListView adapter, called hasStableIds (), has a method overridden for the BaseExpandableListAdapter class to return true. An example is given below.

 override fun hasStableIds(): Boolean {
   return true
 }

Hope it helps! Thank.

PS code is in Kotlin.

0
source

All Articles