ExpandableListview - 单击子项目时更新组视图的UI

时间:2014-08-28 08:15:14

标签: android expandablelistview expandablelistadapter

我在我的应用中集成了可扩展列表视图。我有两个问题。

  1. 我正在尝试在单击子视图项时更新组视图标签的UI。但是我的问题是我无法访问getChildView()方法中的组视图标签。

  2. 如何制作一些子项目是单项选择,其他一些是Multichoice Listview。

  3. 我尝试了很多,但我无法找到答案。请任何人帮助我。

    Code
    public class ExpandableListAdapter extends BaseExpandableListAdapter {
    
        private Context _context;
        private List<String> _listDataHeader; // header titles
        // child data in format of header title, child title
        private HashMap<String, List<String>> _listDataChild;
    
        public ExpandableListAdapter(Context context, List<String> listDataHeader,
                HashMap<String, List<String>> listChildData) {
            this._context = context;
            this._listDataHeader = listDataHeader;
            this._listDataChild = listChildData;
        }
    
        @Override
        public Object getChild(int groupPosition, int childPosititon) {
            return this._listDataChild.get(this._listDataHeader.get(groupPosition))
                    .get(childPosititon);
        }
    
        @Override
        public long getChildId(int groupPosition, int childPosition) {
            return childPosition;
        }
    
        @Override
        public View getChildView(final int groupPosition, final int childPosition,
                boolean isLastChild, View convertView, final ViewGroup parent) {
    
            final String childText = (String) getChild(groupPosition, childPosition);
            LayoutInflater infalInflater = (LayoutInflater) this._context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.list_item, null);
            final Button btnListChild = (Button) convertView
                    .findViewById(R.id.btnAttributeListItem);
            btnListChild.setText(childText);
            btnListChild.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
    
                    btnListChild
                            .setBackgroundResource(R.drawable.attributes_custom_selected_button);
                }
            });
    
            return convertView;
        }
    
        @Override
        public int getChildrenCount(int groupPosition) {
            return this._listDataChild.get(this._listDataHeader.get(groupPosition))
                    .size();
        }
    
        @Override
        public Object getGroup(int groupPosition) {
            return this._listDataHeader.get(groupPosition);
        }
    
        @Override
        public int getGroupCount() {
            return this._listDataHeader.size();
        }
    
        @Override
        public long getGroupId(int groupPosition) {
            return groupPosition;
        }
    
        @Override
        public View getGroupView(int groupPosition, boolean isExpanded,
                View convertView, ViewGroup parent) {
            String headerTitle = (String) getGroup(groupPosition);
    
            // inflate the layout
            LayoutInflater infalInflater = (LayoutInflater) this._context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.list_group, null);
    
            TextView lblListHeader = (TextView) convertView
                    .findViewById(R.id.lbAttributeHeader);
            lblListHeader.setText(headerTitle);
    
            return convertView;
        }
    
        @Override
        public boolean hasStableIds() {
            return false;
        }
    
        @Override
        public boolean isChildSelectable(int groupPosition, int childPosition) {
            return true;
        }
    
    }
    

0 个答案:

没有答案