获取复选框的exapndablelistview onClick事件的childitem数据

时间:2017-04-06 06:02:08

标签: android checkbox expandablelistview

在我的应用程序中,我有一个expandablelistview,其中包含childlist中的复选框。 可扩展列表视图的所有数据都是从webservice获取的。

现在我想获取特定子raw的数据,其中选中了复选框。此外,我还必须执行多项选择操作。 我想,当单击复选框时,所选原始数据将存储在数组中。

这是我的适配器类:

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

        ServiceChildList child = (ServiceChildList) getChild(groupPosition,
                childPosition);
        if (convertView == null)
        {
            LayoutInflater infalInflater = (LayoutInflater) context
                    .getSystemService(context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.item_row, null);
        }
        TextView one = (TextView) convertView.findViewById(R.id.Subservicename);
        one.setText(child.getvName().toString());

        TextView two = (TextView) convertView.findViewById(R.id.Subservicetime);
        two.setText(child.getvDuration().toString());

        TextView three = (TextView) convertView.findViewById(R.id.Subserviceprice);
        three.setText("$" +child.getfPrice().toString()+".00");

        TextView four= (TextView)convertView.findViewById(R.id.Subserviceid);
        four.setText(child.getiSubServiceId().toString());

        CheckBox check=(CheckBox)convertView.findViewById(R.id.sub_check);

        check.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

                CheckBox cb = (CheckBox) buttonView ;
                ServiceChildList cList = (ServiceChildList) cb.getTag();
                cList.setChecked( cb.isChecked() );

            }
        });
        check.setTag( child );
        // Display planet data
        check.setChecked( child.isChecked() );

        return convertView;

    }

这是我的活动课程:

ExpandList.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {

            @Override
            public boolean onChildClick(ExpandableListView parent, View v,
                                        int groupPosition, int childPosition, long id)
            {

                ArrayList<ServiceChildList> ch_list = ExpListItems.get(groupPosition).getSub();

                int len = ExpandList.getChildCount();
                SparseBooleanArray checked = ExpandList.getCheckedItemPositions();
                for (int i = 0; i < len; i++)
                    if (checked.get(i)) {
                        String item = cont_list.get(i);
  /* do whatever you want with the checked item */
                    }


                String child_name = ch_list.get(childPosition).getvName();
                Log.d("dsijirji",child_name);
                String child_id = ch_list.get(childPosition).getiSubServiceId();
                Log.d("dsijirji",child_id);

                showToastMsg( child_id+"\n" + child_name);

                Toast.makeText(getApplicationContext(), child_name, Toast.LENGTH_SHORT ).show();
                Toast.makeText(getApplicationContext(), String.valueOf(groupPosition), Toast.LENGTH_SHORT ).show();
                return false;
            }
        });

告诉我哪里弄错了。帮我这个.. 提前谢谢。

0 个答案:

没有答案
相关问题