为什么展开式事件点击子视图也会对另一组孩子产生影响?

时间:2019-06-26 07:02:23

标签: android android-listview android-expandable-list-view

在第一手的子按钮上,我添加了一个单击按钮侦听器,但是当我单击该按钮时,另一个组上的子按钮也起作用。

@Override
    public View getChildView(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.list_row_group, null);
        }

        TextView newsBtn = convertView.findViewById (R.id.btn_news_list);
        LinearLayout newsContent = convertView.findViewById (R.id.news_list_content);
        newsContent.setVisibility(View.GONE);

        newsBtn.setOnClickListener (new View.OnClickListener () {
            @Override
            public void onClick(View v) {
                View parent = (View) v.getParent().getParent().getParent();
                LinearLayout content = parent.findViewById(R.id.news_list_content);
                TextView btn = (TextView) v ;
                if (content.getVisibility() == View.VISIBLE) {
                    AnimationUtils.slideDown(content);
                    btn.setText("+");
                } else {
                    AnimationUtils.slideUp(content);
                    btn.setText("-");
                }
            }
        });

        return convertView;
    }

0 个答案:

没有答案