1

我有一个可扩展的列表视图,其每个组项都有按钮。有什么方法可以区分按钮点击和项目点击?我希望该按钮单击以展开列表。当项目单击以打开活动时

非常感谢

编辑:更多解释

这大致是我想做的事情,现在我正在考虑使用 ExpandableListView 但我不知道该怎么做。

如您所见,我的组行有两个部分,箭头(我有一个自定义箭头)和文本部分。如果用户点击红色部分,那么我想展开(典型的可扩展列表),如果用户点击绿色部分,那么它会将他们带到一个活动中。

请,任何想法如何! 在此处输入图像描述

注意:这个问题以前由@snake 提出。我有类似的问题,所以复制它。

设置可扩展适配器的代码:

mGroupCollection = new ArrayList<GroupEntity>();

    //
    // for (int number = 0; number < list_related.size(); number++) {
    // System.out.println("the index of the gi"+number);
    // GroupItemEntity gi = ge.new GroupItemEntity();
    //
    // gi.Name = list_related.get(number);
    // System.out.println("to check index value"+gi.Name);
    // ge.GroupItemCollection.add(gi);
    // }
    //
    // mGroupCollection.add(ge);
    //

    for (int number = 1; number <= 6; number++) {
        GroupEntity ge = new GroupEntity();

        switch (number) {
        case 1:
            ge.Name = "MY LEARNING OPTIONS";

            break;
        case 2:
            ge.Name = "MY CAREER TOOLS";

            GroupItemEntity gi_c1 = ge.new GroupItemEntity();
            gi_c1.Name = "Career Options";
            ge.GroupItemCollection.add(gi_c1);
            GroupItemEntity gi_c2 = ge.new GroupItemEntity();
            gi_c2.Name = "Salary BenchMark";
            ge.GroupItemCollection.add(gi_c2);
            GroupItemEntity gi_c3 = ge.new GroupItemEntity();
            gi_c3.Name = "Reading List";
            ge.GroupItemCollection.add(gi_c3);


            break;
        case 3:
            ge.Name = "MY JOURNAL";

            GroupItemEntity gi_j1 = ge.new GroupItemEntity();
            gi_j1.Name = "NoteBook";
            ge.GroupItemCollection.add(gi_j1);
            GroupItemEntity gi_j2 = ge.new GroupItemEntity();
            gi_j2.Name = "Calendar";
            ge.GroupItemCollection.add(gi_j2);
            GroupItemEntity gi_j3 = ge.new GroupItemEntity();
            gi_j3.Name = "Favourites";
            ge.GroupItemCollection.add(gi_j3);


            break;



        case 4:

            ge.Name = "EVENTS";
            GroupItemEntity gi_events = ge.new GroupItemEntity();

            break;

        case 5:
            ge.Name = "PRESS RELEASE";
            GroupItemEntity gi_press = ge.new GroupItemEntity();

            break;


        case 6:
            ge.Name = "ABOUT";
            GroupItemEntity gi_about = ge.new GroupItemEntity();

            break;

        }

        mGroupCollection.add(ge);

    }

    // ge.Name = "commnets";

    adapterexpand = new ExpandableListMainFragmentAdapter(getActivity(),
            lv, mGroupCollection);
    System.out.println("I reached here in case" + adapterexpand);

    lv.setAdapter(adapterexpand);

我的组点击可扩展列表代码:

  lv.setOnGroupClickListener(new OnGroupClickListener() {

        @Override
        public boolean onGroupClick(ExpandableListView parent, View v,
                int groupPosition, long id) {
            String planet = adapterexpand.getGroupValue(groupPosition)
                    .toString();
            System.out.println("this is from details" + planet.trim());
            //Fragment newContent = null;
            switch (groupPosition) {

            case 0:
                Intent intentcourse = new Intent(getActivity(),
                        LearnMainActivity.class);

                startActivity(intentcourse);


                break;
            case 1:

                //Intent intentcareer = new Intent(getActivity(),
                        //CareerToolMainActivity.class);
                //startActivity(intentcareer);

                break;
            case 2:


                break;

            case 3:
                Intent intentevent = new Intent(getActivity(),
                        EventsMainActivity.class);
                startActivity(intentevent);
                break;

            case 4:

                Intent intentspeech = new Intent(getActivity(),
                        SpeechMainActivity.class);
                startActivity(intentspeech);

                break;
            case 5:
                //newContent = new ColorFragment(android.R.color.black);

                break;

            }

            return false;
        }

    });

这是处理子点击的方式:

    lv.setOnChildClickListener(new ExpandableListView.OnChildClickListener()
    {
        @Override
        public boolean onChildClick(ExpandableListView parent, View v, int group_position, int child_position, long id)
        {
        if (group_position==2)
        {
            //Fragment newContent = null;
            switch (child_position) {

            case 0:
                Intent intentcourse = new Intent(getActivity(),
                        NoteBookMain.class);

                startActivity(intentcourse);

                break;
            case 1:
                Intent intentcal = new Intent(getActivity(),
                        SimpleCalendarViewActivity.class);
                startActivity(intentcal);



                break;
            case 2:

                break;

            case 3:


            case 4:
            //  newContent = new ColorFragment(android.R.color.white);

                break;


            }

            System.out.println("clicked parent " + group_position + " child "
                    + child_position);

        }
            return false;

        }

    });
4

0 回答 0