在Expandablelistview奇怪的行为 - 机器人 [英] Strange behaviour in Expandablelistview - Android

查看:137
本文介绍了在Expandablelistview奇怪的行为 - 机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着去实现使用ExpandableListView一个活动,我已经得到了这么远,但现在我已经发现了一些奇怪的行为。

Im trying to implement an activity that uses ExpandableListView and I have gotten so far but now I have found some strange behavior.

我的活性是指所指定的用户记录的食物摄取。他们的菜单(早餐,午餐和晚餐 - 外组)的选择,它展开显示它们的内容。 当用户点击一个内部菜单项出现一个对话框,询问他们的数量。一旦他们进入一个数量,并关闭该对话框中的菜单项的文本更改,以反映该项目已被消耗的数量

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

上面的图像示出的清单中的关闭状态。

The above image shows the list in a closed state.

下面的列表中我已经打开了的午餐菜单,点击薯片,并表示为1。数量正如你所看到的'土豆'itemtext现在已更改,以反映1的数量后。

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.

奇怪的一部分,现在情况发生。如果我点击'午餐',并关闭列表,然后再次单击它重新打开它,在数量x 1的文本已经跃升到另一个项目(牛奶)

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)

每次我打开和关闭它跳跃来回两个项目的名单。另外,如果我打开了其他项目,如早餐,我发现他们也有现在得到的物品以数量x 1',即使我没有点击它们。

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.

的code是相关的位是这样:

The bits of code that are relevant are as such:

XML的一个子元素:

The XML for a child element:

<?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>

在code这就是触发点击一个子元素:

The code thats triggered on clicking a child element:

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会打开一个对话框,接受一个值量,追加列表元素来反映这一点,也保存到数据库,并设置与所选择的项目和数量的TextView。

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.

对不起,只是转储code整个负载,但这我难倒,希望有人能提供帮助。

Sorry to just dump a whole load of code, but this has me stumped and hopefully someone can help.

感谢

凯文

推荐答案

我不认为这个问题是与对话。我有同样的问题在我的项目,不能修复它。我想打开孩子当 ExpandableListView 有一个bug。我只有一个孩子每个组,当我展开一组,孩子转移到另一组。经过测试,我发现,当我扩大了孩子们重新加载。

I don't think the problem is with the dialogs. I had the same problem in my project and couldn't fix it. I think the ExpandableListView has a bug when opening children. I had only one child per group and when I expand a group, the child moves to another group. After testing, I found out that when I expand the children are reloaded.

这篇关于在Expandablelistview奇怪的行为 - 机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆