可展开列表视图子单击“侦听器”

时间:2012-08-02 11:11:54

标签: android expandablelistview android-alertdialog

我有一个非常简单的问题。在包含exxpandable列表视图的对话框中,当我单击一个孩子时,我想做一些操作并返回到活动。我setOnChildClickListener()setOnGroupClickListener()的点击事件都在运行,但我的alertdialog并未关闭。我想关闭孩子点击列表并关闭我的alertdialog并返回我的活动。任何人都可以帮忙吗?

代码:

final AlertDialog.Builder builder = new AlertDialog.Builder(
                    TestActivity.this);

        ExpandableListView dialogExpandableListView = new ExpandableListView(
                this);
        dialogExpandableListView
                .setAdapter(new EfficienctExpandableAdapter(
                        this));
        dialogExpandableListView
                .setOnChildClickListener(new ExpandableListView.OnChildClickListener() {

                    @Override
                    public boolean onChildClick(ExpandableListView arg0,
                            View arg1, int arg2, int arg3, long arg4) {
                        // TODO Auto-generated method stub

                        Log.d("skt", "clicked parent " + arg2 + " child "
                                + arg3);

                        return false;
                    }
                });

        dialogExpandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {

            @Override
            public boolean onGroupClick(ExpandableListView arg0, View arg1, int arg2,
                    long arg3) {
                // TODO Auto-generated method stub

                Log.d("skt", "group click --- clicked parent " + arg2);
                return false;
            }
        });

        builder.setView(dialogExpandableListView);

        builder.create();
        builder.show();

1 个答案:

答案 0 :(得分:0)

我想你开始在这里展示Alertdialog了

    builder.setView(dialogExpandableListView); 
    builder.create();
    builder.show();

但你还没有在任何地方取消alertView。

尝试取消alertView here

 @Override
                public boolean onChildClick(ExpandableListView arg0,
                        View arg1, int arg2, int arg3, long arg4) {
                 Log.d("skt", "clicked parent " + arg2 + " child "
                             + arg3);
                 builder.cancel();
                 //or
                 builder.dismiss();
                 return false;

   }

希望有所帮助