How to create on click event for children in Expandable list

后端 未结 3 786
长发绾君心
长发绾君心 2021-01-02 23:49

I am playing around with this example. http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/ExpandableList2.html

I cannot figure

相关标签:
3条回答
  • 2021-01-03 00:14

    You should override onChildClick in your ExpandableListActivity extension.

    0 讨论(0)
  • 2021-01-03 00:18

    You need to subscribe to setOnChildClickListener

    getExpandableListView().setOnChildClickListener(this);
    

    and implement OnChildClickListener

    @Override
    public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,
            int childPosition, long id) {
        // use groupPosition and childPosition to locate the current item in the adapter
        return true;
    }
    
    0 讨论(0)
  • 2021-01-03 00:20

    You should specify location of items in expandable list like this

    listView.setOnChildClickListener(new OnChildClickListener()
    {
        @Override
        public boolean onChildClick(ExpandableListView parent, View v, int group_position, int child_position, long id)
        {
            if(group_position==0 && child_position==0){
                TryFragment secondFragment = (TryFragment) SampleActivity.this.getFragmentManager().findFragmentById(R.id.tryFragment);
                secondFragment.getView().setVisibility(View.VISIBLE);
            } else if(group_position==2 && child_position==2){
                TryFragment secondFragment = (TryFragment) SampleActivity.this.getFragmentManager().findFragmentById(R.id.tryFragment);
                secondFragment.getView().setVisibility(View.VISIBLE);
            }
            return false;
        }
    });
    
    0 讨论(0)
提交回复
热议问题