在扩展列表视图访问子项的个人ojects [英] Access Child Item's individual ojects in Expandable Listview

查看:177
本文介绍了在扩展列表视图访问子项的个人ojects的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何访问子项的子视图在任何一组视图列表视图扩展??

How do I access the child views of child items in any group view in expandable listview??

selectAll.setOnClickListener(new View.OnClickListener(){
@Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
             int gourpsSum = adapter.getGroupCount();  
             for(int i = 0; i < gourpsSum; i++) {  
                 int childSum = adapter.getChildrenCount(i);
                 for(int k = 0; k < childSum;k++) {  
                     boolean isLast = false;  
                     if (k == (childSum - 1)){   
                         isLast = true;  
                     }  

                     CheckBox cBox = (CheckBox) adapter.getChildView(i, k, isLast, null, null).findViewById(R.id.checkBox);  
                     cBox.setChecked(selectAll.isChecked());
                     ((BaseExpandableListAdapter) adapter).notifyDataSetChanged(); 
                 }  

             }  
        }  
});

,其中全选是可扩展列表视图在另一个上面复选框。

where selectAll is another Checkbox above the expandable listview.

推荐答案

您需要做一个类来扩展的 BaseExpandableListAdapter ,然后重写抽象的<一个href=\"http://developer.android.com/reference/android/widget/ExpandableListAdapter.html#getChildView(int,%20int,%20boolean,%20android.view.View,%20android.view.ViewGroup)\"相对=nofollow> getChildView()的方法,该方法是基于groupPosition和childPosition以确定哪个视图被显示。您也可以访问这个扩展列表查看教程

You need to make a class to extend the BaseExpandableListAdapter, and then override the abstract getChildView() method, this method is based on groupPosition and childPosition to determine which view to be displayed. You can also visit this Expandable List View tutorial.

在本教程中,它显示了如何访问TextView的对象在每个子视图,如果您要访问的复选框,可以做类似的事情。下面是一个示例code:

In the tutorial, it shows how to access the TextView object in each child view, if you want to access the CheckBox, you can do the similar thing. Below is a sample code:

    @Override
    public View getChildView(int groupPosition, final int childPosition,
            boolean isLastChild, View convertView, ViewGroup parent) {

        final String childText = (String) getChild(groupPosition, childPosition);

        if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) this._context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.list_item, null);
        }

        TextView txtListChild = (TextView) convertView
                .findViewById(R.id.lblListItem);
        CheckBox checkboxListChild = (CheckBox) convertView
                .findViewById(R.id.checkboxListItem); //assume thats the id of your checkbox object


        txtListChild.setText(childText);
        return convertView;
    }

您还可以检查出本教程了解ExpandableListView使用复选框。

You can also check out this tutorial to learn about ExpandableListView with checkbox.

这篇关于在扩展列表视图访问子项的个人ojects的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆