How to get onChildClick value from expandablelistview in android?

后端 未结 3 1459
陌清茗
陌清茗 2021-02-06 15:58

I am working on a project with parsing JSON from url to ExpandableListView. Depending on the \"status\" tag value (active or pending) , will be placing records accordingly to to

3条回答
  •  有刺的猬
    2021-02-06 16:39

    The below isn't perfect but it works. It might be helpful to those who need to access the view without overriding the onChildClick method such as a custom dialog with an ExpandableListView.

        ExpandableListView ellQuickKeys = (ExpandableListView) layout.findViewById(R.id.ellQuickKeys);
    
        SimpleExpandableListAdapter expListAdapter =
                new SimpleExpandableListAdapter(
                                this,
                                createGroupList(),                              // Creating group List.
                                R.layout.group_row,                             // Group item layout XML.                       
                                new String[] { "Group Item" },  // the key of group item.
                                new int[] { R.id.row_name },    // ID of each group item.-Data under the key goes into this TextView.                                   
                                createChildList(),                              // childData describes second-level entries.
                                R.layout.child_row,                             // Layout for sub-level entries(second level).
                                new String[] {"Sub Item"},              // Keys in childData maps to display.
                                new int[] { R.id.lblChildText}             // Data under the keys above go into these TextViews.
                        );
    
        ellQuickKeys.setOnChildClickListener(new OnChildClickListener() {    
            public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,int childPosition,long id) {
                Log.d("Selected text: " + ((TextView) v.findViewById(R.id.lblChildText)).getText());
    
                return false;
            }
        });
        ellQuickKeys.setAdapter(expListAdapter);
    

    child_row.xml

    
    
    
    
    
    
    

提交回复
热议问题