0

我可以使用正确的 groupcursors 和 childcursorsSimpleCursorTreeAdapter创建。ExpandableListView对于我的程序,每个孩子包含三个TextViews。当我展开组并单击子项时,我使用自定义对话框在EditText视图中显示三个值。

如果我一次只打开“一个”组,该程序就可以了。如果单击,我可以获得正确的子值。但是如果我同时扩展几个组。它只显示最新组下的最新孩子。

例如:A 组有 3 个项目,B 组有 5 个项目,C 组有 2 个项目。先点A组下的children,没问题,再点B组下的children,没问题,但是如果我回头再点击A组下的child,还是显示B组下的child,不知道怎么显示正确孩子们。如果我用Toast来展示,所有的孩子都是正确的,太奇怪了。我可以用这种方法做什么?

epView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() 
        {
            @Override
            public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long row) 
            { 
             return false;  
            }
            });

        epView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
        @Override
        public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) 
        {

         int tempid = childcursor.getInt(0);
         String temp1 = childcursor.getString(1);
            String temp2 = childcursor.getString(2);
            String temp3 = childcursor.getString(3);
            CustomDialog custom = new CustomDialog(ListCateActivity.this,catecursor,childcursor,temp1,temp2,temp3,tempid);
            custom.setTitle("Record Information");
            custom.show();

            Toast.makeText(ListCateActivity.this, "Group:"+String.valueOf(groupPosition).toString()+" Child: "+String.valueOf(childPosition).toString()+temp1+" "+temp2+" "+temp3, Toast.LENGTH_SHORT).show();
            return true;
        }
        });

谢谢 !!

4

1 回答 1

0

终于我知道我的代码现在发生了什么,但这太奇怪了。当我在 getChildrenCursor 方法中定义 childcursor 时。它应该被继承,因为我将 childcursor 定义为实例变量,因此它可以在类之间共享。无论如何,Java 和 Android 很有趣。但是当您遇到意外结果时,您需要调试以找出问题所在。

于 2010-11-25T23:24:09.230 回答