如何在FlowLayout中动态添加TextView左侧的EditText?

时间:2017-12-01 10:41:57

标签: android flowlayout

enter image description here

我已创建添加到TextViews的动态FlowLayout数组列表。现在,当点击EditText时,我必须在每个TextView左侧添加一个ImageView

代码:

FlowLayout.LayoutParams params = new FlowLayout.LayoutParams(
                FlowLayout.LayoutParams.WRAP_CONTENT, FlowLayout.LayoutParams.WRAP_CONTENT);
        params.setMargins(5, 5, 5, 5);
        mFlowLayout.removeAllViews();
        View[] view = new View[2];
        for (int i = 0; i < 2; i++) {
            view[i] = LayoutInflater.from(getActivity()).inflate(R.layout.item_rich_element_edit_flow_layout
                    , mFlowLayout, false);
            view[i].setId(i);
            view[i].setTag(i);
            TextView textView = view[i].findViewById(R.id.text_view_attribute_name);
            ImageView imageView = view[i].findViewById(R.id.image_view_left_cursor);
            imageView.setTag(i);
            imageView.setOnClickListener(view1 -> addView((Integer) view1.getTag(), view1));
            textView.setText(element.getElementName());
            mFlowLayout.addView(view[i]);
        }

0 个答案:

没有答案