android更新特定的子项扩展列表视图

时间:2017-07-03 05:22:55

标签: android expandablelistview expandablelistadapter

我有一个可扩展的列表视图,在每个子视图中都有开关。 我想改变特定孩子的开关。

这是我的getChildView函数:

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


        if (convertView == null) {
            LayoutInflater layoutInflater = (LayoutInflater) this.context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = layoutInflater.inflate(R.layout.node_child, null);
        }

        TextView switchTitleTextView = (TextView) convertView
                .findViewById(R.id.switchName);
        switchTitleTextView.setText("Switch " + (expandedListPosition + 1));

        final StickySwitch stickySwitch = (StickySwitch)  convertView.findViewById(R.id.sticky_switch);

        stickySwitch.setOnSelectedChangeListener(new StickySwitch.OnSelectedChangeListener() {
            @Override
            public void onSelectedChange(@NotNull StickySwitch.Direction direction, @NotNull String text) {

                if(direction == StickySwitch.Direction.RIGHT) {

                    try {
                        Log.d("Switch RIGHT", "Pressed");


                    } catch (JSONException e) {
                        e.printStackTrace();
                    }

                }

                if(direction == StickySwitch.Direction.LEFT) {

                    try {
                        Log.d("Switch LEFT", "Pressed");

                    } catch (JSONException e) {
                        e.printStackTrace();
                    }

                }
            }
        });

        return convertView;
    }

现在我必须改变特定开关的方向。说第4组和第2组。我不确定如何更新特定的孩子并将其更改为向左或向右。

0 个答案:

没有答案